You can use Array.prototype.flat()
Note: All the methods below are just alternative which will have high speed. Your solution has O(n)
time-complexity and all the method below have same time-complexity. The time-complexity of merging two arrays is O(n)
not O(1)
let arr = [[{x: 1},{y: 2}],[{z: 3}]]
let objs = arr.flat();
console.log(objs)
Or another way is using concat()
and reduce()
let arr = [[{x: 1},{y: 2}],[{z: 3}]]
let objs = arr.reduce((ac,a) => ac.concat(a),[])
console.log(objs)
A better idea suggested in comments is using apply()
let arr = [[{x: 1},{y: 2}],[{z: 3}]]
let objs = [].concat.apply([], arr)
console.log(objs)