Premium Only Content

`_.uniq` function on array using JavaScript Library underscore.js ( #shorts )
Hi Friends,
`_.uniq` function on array using JavaScript Library underscore.js
`_.uniq` is also utility function in Underscore.js library that allows you to create a new array that contains only the unique elements from an existing array.
In below example, we have an array `people` that contains duplicate objects with different ages. We use `_.uniq` with an iteratee function that returns the person's name, to create a new array `uniquePeople` that contains only the unique objects based on their name. The resulting `uniquePeople` array contains the objects for Harry, Peter, and Ronnie but only the first occurrence of Harry is included because the iterate function returns the same value for both Harry objects.
// syntax
_.uniq(array, [isSorted], [iteratee])
//example
var people = [
{ name: "Harry", age: 30 },
{ name: "Peter", age: 25 },
{ name: "Harry", age: 35 },
{ name: "Ronnie", age: 30 },
];
var uniquePeople = _.uniq(people, false, function (person) {
return person.name;
});
console.log(uniquePeople);
// [
// { name: "Harry", age: 30 },
// { name: "Peter", age: 25 },
// { name: "Ronnie", age: 30 }
// ]
#javascript #under #score #underscore #underscorejs #uniq #underscoreuniq #uniqfunction #unique #object #array #string #nodejs #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #coders #development #code #dev #interview #php #trend #trending #answer #laravel #youtube #instagram #socialmedia #education #edit #how #india #knowledge #quiz #reels #short #subscribe #share #update #video #web #webdeveloper #website #webdesign #ytshorts #youtuber #princecheema_official @princecheema_official
-
LIVE
Dr Disrespect
7 hours ago🔴LIVE - DR DISRESPECT - TRIPLE THREAT CHALLENGE - WZ, PUBG, TARKOV
10,244 watching -
LIVE
Nerdrotic
5 hours ago $8.30 earnedSnow White BOMBS, Marvel Desperation, Amazon Studio Head QUITS! - Friday Night Tights 347
5,003 watching -
2 MIKES LIVE
2 hours ago2 MIKES LIVE #198 Open Mike Friday with guest Danielle Francine!
69 -
LIVE
LFA TV
5 hours agoCanada Aims to Inflict as Much Pain as Possible on Americans | TRUMPET DAILY 3.28.25 7PM
157 watching -
10:21
Tactical Advisor
2 hours agoThe Gun You NEVER Thought You Needed | Volquartsen ENV
251 -
LIVE
The Amber May Show
6 hours ago $0.17 earnedWhat They Did To Survive Late Stage Breast Cancer| Tom Renz
241 watching -
8:41
ARFCOM News
3 hours ago $0.19 earned😍 Kash Patel LOVES The ATF 😍 | Here's Why Vanderstok Isn't A Catastrophe | Veto Record !!!
4.31K1 -
20:41
Rena Malik, M.D.
1 day ago $0.13 earnedHow Much Protein Do You Actually Need, based on Science ft. Dr. Allan Bacon
5.1K1 -
1:06:02
In The Litter Box w/ Jewels & Catturd
23 hours agoTRUMP WALKS THE TALK | In the Litter Box w/ Jewels & Catturd – Ep. 772 – 3/28/2025
66.3K51 -
14:11
Talk Nerdy Sports - The Ultimate Sports Betting Podcast
3 hours ago3/28/25 -Fire Friday: 5 Bets, 3 Parlays & 1 Stone Cold Lock That Books Fear
24K1