如何使用 lodash 联合数组内部的数组?
例如:
Input:
var x = [ [1,2,3,4], [5,6,7], [], [8,9], [] ];
Expected output:
x = [1,2,3,4,5,6,7,8,9];
目前我的代码执行以下操作:
return promise.map(someObjects, function (object)) {
return anArrayOfElements();
}).then(function (arrayOfArrayElements) {
// I tried to use union but it can apply only on two arrays
_.union(arrayOfArrayElements);
});
最佳答案
使用apply
将数组值作为参数传递的方法:
var union = _.union.apply(null, arrayOfArrayElements);
关于javascript - 使用 lodash 的数组内部数组联合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37311639/