Last Updated: February 25, 2016
·
2.7K
· 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']

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside