Sample Data
const data = [{ id: 1,iitems: [{ id: 1, name: 'R1'}]},{id: 2, items: [{ id: 1, name: 'R2'},{ id: 1, name: 'R3'}]}];
data.map((item) => item.items).data.reduce((acc, curr) => acc.concat(curr), [])
console.log(data)
What I'm trying to do here is to merge the nested to one array. but the output is like this.
data = [
{ id: 1, name: 'R1'},
{ id: 1, name: 'R2'},
{ id: 1, name: 'R3'}]
Expected output:
data = [
{ id: 1 },
{ id: 1, name: 'R1' },
{ id: 2 },
{ id: 1, name: 'R2'},
{id: 1, name: 'R3'}
];
{ "id": 1, "name": "R2"}not in your expected output?itemsif you want an array and an array of objects you want references to the original ids?