I need to merge two object, with an array inside, together :
res : [ { data: [1,2,3] }, { data: [4,5,6] } ]
And the result will look like this :
res : [1,2,3,4,5,6]
How can I get there ?
Thank you !
I need to merge two object, with an array inside, together :
res : [ { data: [1,2,3] }, { data: [4,5,6] } ]
And the result will look like this :
res : [1,2,3,4,5,6]
How can I get there ?
Thank you !
You can use Array.reduce along with Array.concat:
let input = [ { data: [1,2,3] }, { data: [4,5,6] } ];
let result = input.reduce((result, entry) => result.concat(entry.data), []);
console.log(result);