如何将数组中的对象与ES6扩展运算符合并?假设我们有这样的对象:
let arr = [{ a: 1, b: true }, { c: "val", d: null }];这个物体的结果是:
{ a: 1, b: true, c: "val", d: null };发布于 2019-05-15 07:00:28
您可以将这些元素扩展到Object.assign中,而无需进一步循环。
let arr = [{ a: 1, b: true }, { c: "val", d: null }],
result = Object.assign({}, ...arr);
console.log(result);
发布于 2019-05-15 06:57:38
https://stackoverflow.com/questions/56143349
复制相似问题