Dev Helpers
← Back

Remove a withdrawn candidate and close ranks

Remove a withdrawn candidate and close ranks. Inspect the transformed data in the console.

Open this example in the interactive library

Source code

const rows = [
  { name: "Ada", picks: ["A", "C", "B"] },
  { name: "Kim", picks: ["C", "A", "B"] },
  { name: "Leo", picks: ["A", "B", "C"] },
];
const result = rows.map((r) => ({
  ...r,
  picks: r.picks.filter((p) => p !== "A"),
}));
console.log(JSON.stringify(result, null, 2));

Sample output

[
  {
    "name": "Ada",
    "picks": [
      "C",
      "B"
    ]
  },
  {
    "name": "Kim",
    "picks": [
      "C",
      "B"
    ]
  },
  {
    "name": "Leo",
    "picks": [
      "B",
      "C"
    ]
  }
]