使用lodash按属性加入对象数组

Kin*_*rog 1 javascript arrays

有没有办法使用lodash或其他库来加入一个对象数组?

我正在寻找一个现成的功能而不是for循环.

例如:

[{a: 1}, {a:3}, {a: 4}]
      //Run a function by specifing the property a and setting "," as the delimeter
Get 1,3,4
Run Code Online (Sandbox Code Playgroud)

Rob*_* M. 5

您不需要lodash,只需使用map和即可join

let collection = [{a: 1}, {a:3}, {a: 4}];
alert(collection.map(item => item.a).join(','));
Run Code Online (Sandbox Code Playgroud)


Kev*_* Le 5

这是你的回答

var arr = [{a: 1}, {a:3}, {a: 4}];
var s = _.map(arr, 'a').join(',');
//s == '1,2,3,4'
Run Code Online (Sandbox Code Playgroud)