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
-
2:55:43
TimcastIRL
7 hours agoTrump DOJ To Ban Trans People From Owning Guns After Catholic School Shooting | Timcast IRL
181K107 -
3:21:36
The Quartering
6 hours agoBaldur's Gate 3 First Playthrough!
46.5K7 -
6:34:42
Rallied
8 hours ago $7.39 earnedWarzone Solo Challenges
76.1K2 -
57:40
MattMorseTV
8 hours ago $10.91 earned🔴Trump just SHATTERED the RECORD.🔴
54.2K90 -
43:39
WickedVirtue
5 hours agoLate Night Spooky Plays
37K2 -
2:04:02
Glenn Greenwald
8 hours agoTrump and Rubio Apply Panama Regime Change Playbook to Venezuela; Michael Tracey is Kicked-Out of Epstein Press Conference; RFK Senate Hearing | SYSTEM UPDATE #508
111K138 -
58:36
Total Horse Channel
10 hours ago2025 CSI3* A Coruña Porsche - Grand Prix
28.3K -
2:10:32
megimu32
6 hours agoOTS: Mighty Morphin Power Rangers & the 90s Movie That Defined a Generation
25.3K12 -
1:14:53
Badlands Media
21 hours agoTHE SITREP Ep. 128: Gun Rights, Sleep Paralysis, and Venezuela Cartel Strikes
44.5K11 -
2:44:56
BubbaSZN
6 hours ago🔴 LIVE - FORTNITE WITH NEW KEYBOARD
16.4K1