0
有沒有使用lodash或其他庫來加入對象數組的方法?按屬性使用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
有沒有使用lodash或其他庫來加入對象數組的方法?按屬性使用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
你並不需要爲這個lodash,你可以只使用map
和join
:
let collection = [{a: 1}, {a:3}, {a: 4}];
alert(collection.map(item => item.a).join(','));
這裏是你的答案lodash
var arr = [{a: 1}, {a:3}, {a: 4}];
var s = _.map(arr, 'a').join(',');
//s == '1,2,3,4'
hehe ecma script ...幸運的人,因爲你被允許使用它=) –
@java_newbie你是絕對正確的,也許你可以讓你的團隊使用一個翻譯和一些polyfills - 值得頭痛! –