`_.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
-
1:17:04
Man in America
7 hours ago🚨 RED ALERT: Milton, Helene & The Plan to DECIMATE the US to Build 15-Minute Cities
32.5K65 -
2:32:11
WeAreChange
7 hours agoBiden EXPOSES Kamala’s Hurricane Fabrication! Musk To Jail??
87.5K70 -
1:18:35
Redacted News
9 hours agoHIGH ALERT "GET OUT NOW OR DIE" FLORIDA OFFICIALS WARN STATE IS ABOUT TO BE DESTROYED | REDACTED
163K830 -
1:10:14
Josh Pate's College Football Show
10 hours agoWeek 7 Predictions: OhioSt vs Oregon | OU vs Texas | PennSt vs USC | OleMiss vs LSU | NEW JP Poll
31.8K4 -
59:57
Flyover Conservatives
23 hours agoWho is “Rich" and How Much Should We Tax “Them”? - Clay Clark; Economic Update - Dr. Kirk Elliott | FOC Show
36.6K7 -
54:55
LFA TV
1 day agoDemocrats in No Rush to Help Disaster Victims Vote | Trumpet Daily 10.8.24 9PM EST
28.2K10 -
LIVE
Tundra Gaming Live
6 hours agoThe Worlds Okayest Slayer Of Undead Hords Becomes Spiritborn
1,347 watching -
59:21
Edge of Wonder
8 hours agoThe Military Industrial Complex & Breakaway Civilizations?
44.4K12 -
43:02
Chrissy Clark
6 hours agoWedding Recap, Trump On ‘Call Her Daddy’ & MORE! I Underreported Stories
38.5K29 -
1:38:07
vivafrei
10 hours agoKamala Harris Media Blitz is a Political Titanic! Canadian Forest Fire Negligence is CRIMINAL!
107K89