`_.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
LFA TV
7 hours agoDr. Richard Fleming | THE HANNAH FAULKNER SHOW | 7.6.24 @4PM EST
924 watching -
30:30
Stephen Gardner
2 hours ago🔴BREAKING: Trump Trashes Biden while welcoming Kamala Harris
10.5K55 -
15:17
Scammer Payback
3 days agoScammer's Reaction after being Hacked
39.4K60 -
1:26:11
Michael Franzese
19 hours agoMichael Franzese LIVE! | Biden Cover Up and The Power of Second Chances | Ep. 10
29.4K92 -
59:08
UFC - Ultimate Fighting Championship
3 days agoGeorges St-Pierre, Payton Talbott, UFC 303 recap | UFC Unfiltered
40.3K17 -
2:12:05
Tactical Advisor
5 hours agoGun Giveaway Info & New Build Spotlight - Vault Room Live Stream - Vault Room Live Stream
28.5K17 -
1:15:27
JoBlo Originals
20 hours agoFriday Night Flicks!
35.4K7 -
1:00:41
Trumpet Daily
1 day agoJoe Biden’s Demeanor Is ‘Not of This Earth’ - Trumpet Daily | July 5, 2024
57.3K89 -
12:05
Space Ice
1 day agoStar Wars The Acolyte Is So Good The Fans Failed The Critics - Best Movie Ever
50.7K92 -
30:57
Degenerate Plays
23 hours agoDid Gaming Peak Back Then? - Stellar Blade : Part 6
54.4K