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']Written by Héliton Nordt
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Underscore.js
Authors
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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#