我希望将所有对象合并为一个大数组。 例如 我将多个对象数组组合成一个大数组
[
[ { slot: 0, time: '08:00' }, { slot: 1, time: '08:10' } ],
[ { slot: 2, time: '08:20' }, { slot: 3, time: '08:30' } ],
[ { slot: 4, time: '08:40' }, { slot: 5, time: '08:50' } ],
[ { slot: 6, time: '09:00' }, { slot: 7, time: '09:10' } ],
[ { slot: 8, time: '09:20' }, { slot: 9, time: '09:30' } ]
]
我的预期结果是
[
{ slot: 0, time: '08:00' },
{ slot: 1, time: '08:10' },
{ slot: 2, time: '08:20' },
{ slot: 3, time: '08:30' },
{ slot: 4, time: '08:40' },
{ slot: 5, time: '08:50' },
{ slot: 6, time: '09:00' },
{ slot: 7, time: '09:10' },
{ slot: 8, time: '09:20' },
{ slot: 9, time: '09:30' }
]
答案 0 :(得分:1)
您可以将Array.concat
与spread syntax结合使用。
var data = [ [ { slot: 0, time: '08:00' }, { slot: 1, time: '08:10' } ], [ { slot: 2, time: '08:20' }, { slot: 3, time: '08:30' } ], [ { slot: 4, time: '08:40' }, { slot: 5, time: '08:50' } ], [ { slot: 6, time: '09:00' }, { slot: 7, time: '09:10' } ], [ { slot: 8, time: '09:20' }, { slot: 9, time: '09:30' } ] ],
result = [].concat(...data);
console.log(result);