I'm working on extracting data from a deeply nested array.
Here's the initial setup:
layout: {
parent: [
{
type: "tabset",
id: "tab1",
children: [
{
type: "tab",
id: "id1",
},
{
type: "tab",
id: "id2",
},
],
},
{
type: "tabset",
id: "tab2",
children: [
{
type: "tab",
id: "id3",
},
],
},
],},
I need to remove the object with id: "id2" from the input. Here is my attempt:
layout.parent.filter((item) => item.children.filter((el) => el.id !== "id2"));
The desired output:
layout: {
parent: [
{
type: "tabset",
id: "tab1",
children: [
{
type: "tab",
id: "id1",
},
],
},
{
type: "tabset",
id: "tab2",
children: [
{
type: "tab",
id: "id3",
},
],
},
],},
Unfortunately, my code is not producing the desired outcome. Any suggestions or explanations would be greatly appreciated.
Thank you in advance for your help!