I have few arrays with objects and I need to merge them in to one, but next code doesn't works, it return empty array:
let y = [{id:1, value: 'test1'}, {id:2, value: 'test2'}]; let z = [{id:3, value: 'test3'}, {id:4, value: 'test4'}]; let x = [{id:5, value: 'test5'}, {id:6, value: 'test6'}]; let arr = []; arr.concat(...x,...y,...z); console.log(arr);
let arr = [...y, ...x, ...z];arr.concatreturns a new array…!? It does not modifyarrin place.concatcreates a new array. Change it toarr.push(...x,...y,...z)