e5fncg
Last Updated: February 25, 2016
·
1.427K
· hnordt
79f39dbd7c90349087908bb13ab8fb55

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']
Say Thanks
Respond