Underscore.JS - pluck method



Syntax

_.pluck(list, propertyName)

pluck method extract a list of property values from a list of objects.

Example

var _ = require('underscore');

var list = [{name: 'Sam', age: 10}, {name: 'Joe', age: 12}]
//Example 1. invoke pluck method to get all names
var result = _.pluck(list, 'name');
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 'Sam', 'Joe' ]
underscorejs_processing_collection.htm
Advertisements