`_.pluck` function on array using JavaScript Library underscore.js ( #shorts )

1 year ago
11

Hi Friends,

`_.pluck` function on array using JavaScript Library underscore.js

`_.pluck` is a utility function in Underscore.js library that allows you to extract a specific property value from each object in an array of objects. It simplifies the process of retrieving a particular property from multiple objects.

In below example, we have an array of objects students, where each object represents a student with properties such as name and age. We use _.pluck to extract the name property from each object, and the resulting names array contains the names of the students.

Note: starting from Underscore.js version 1.8.0, the _.pluck function has been deprecated in favor of the _.map function with a property shorthand.

// syntax
_.pluck(list, propertyName)

// example
var students = [
{ name: "Alice", age: 20 },
{ name: "Bobby", age: 22 },
{ name: "Charlie", age: 21 }
];
var names = _.pluck(students, "name");
console.log(names);
// ["Alice", "Bobby", "Charlie"]

#javascript #under #score #underscore #underscorejs #underscorepluck #pluckfunction #pluck #object #array #string #nodejs #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #coders #development #code #dev #interview #php #trend #trending #answer #best #free #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 ​

Loading comments...