pluck

pluck(propertyName) -> Array

Optimization for a common use-case of collect: fetching the same property for all the elements. Returns the property values.

Since it avoids the cost of a lexical closure over an anonymous function (like you would do with collect), this performs much better.

Perhaps more importantly, it definitely makes for more concise and more readable source code.

Examples


['hello', 'world', 'this', 'is', 'nice'].pluck('length')
// -> [5, 5, 4, 2, 4]

document.getElementsByClassName('superfluous').pluck('tagName').sort().uniq()
// -> sorted list of unique canonical tag names for elements with this
// specific CSS class...

See also

The invoke method does much the same thing for method invoking.