Last Updated: February 25, 2016
·
2.054K
· hnordt

Use & Abuse: Underscore's pluck

From the official docs (http://underscorejs.org/#pluck):

_.pluck(list, propertyName)
"A convenient version of what is perhaps the most common use-case for map: extracting a list of property values."

pluck is very useful for things like:

var fruits = [
    { name: 'apple', color: 'red' },
    { name: 'banana', color: 'yellow' },
    { name: 'orange', color: 'orange' }
];

_.pluck(fruits, 'name'); // returns ['apple', 'banana', 'orange']