Open this example in the interactive library
Source code
const rows = [
{ task: "design", needs: [] },
{ task: "build", needs: ["design"] },
{ task: "test", needs: ["build"] },
{ task: "ship", needs: ["build", "test"] },
];
const result = rows
.filter((r) => r.task !== "design")
.map((r) => ({ ...r, needs: r.needs.filter((n) => n !== "design") }));
console.log(JSON.stringify(result, null, 2));
Sample output
[
{
"task": "build",
"needs": []
},
{
"task": "test",
"needs": [
"build"
]
},
{
"task": "ship",
"needs": [
"build",
"test"
]
}
]