There is an array for each id key that is not needed. That is kind of a group break.
const header = [
[
{ id: "1",
text: "A",
},
],
[
{ id: "2",
text: "B",
array:[1,2,3],
},
{ id: "2",
text: "B1",
},
],
[
{ id: "3",
text: "A",
},
],
];
The result should be that below. The array between the same id should disapear. Only one array that contains the data as objects should remain.
const header = [
{ id: "1",
text: "A",
},
{ id: "2",
text: "B",
array:[1,2,3],
},
{ id: "2",
text: "B1",
},
{ id: "3",
text: "A",
},
];
What you're trying to archive is called flatten.
JavaScript has the build in method to archive this:
Array.prototype.flat().https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat
Example (taken from the source above)