A convenient version of what is perhaps the most common use-case for map: extracting a list of property values.

很方便的为你提供一个获取列表值的方法

1 var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
2 _.pluck(stooges, 'name');
3 => ["moe", "larry", "curly"]

源码:

1   _.pluck = function(obj, key) {
2     return _.map(obj, function(value){ return value[key]; });
3   };

 

 

posted on 2012-04-23 21:20  himanhimao  阅读(488)  评论(0编辑  收藏  举报