_.pluck
array.map
or .map
can also be used to replace .pluck
. Lodash v4.0 removed .pluck
in favor of .map
with iteratee shorthand. Details can be found in Changelog
- // Underscore/Lodash
- var array1 = [{name: "Alice"}, {name: "Bob"}, {name: "Jeremy"}]
- var names = _.pluck(array1, "name")
- console.log(names)
- // output: ["Alice", "Bob", "Jeremy"]
- // Native
- var array1 = [{name: "Alice"}, {name: "Bob"}, {name: "Jeremy"}]
- var names = array1.map(function(x){
- return x.name
- })
- console.log(names)
- // output: ["Alice", "Bob", "Jeremy"]
Browser Support for Array.prototype.map()
✔ | ✔ | 1.5 ✔ | 9.0 ✔ | ✔ | ✔ |
当前内容版权归 you-dont-need 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 you-dont-need .