Skip to content

Instantly share code, notes, and snippets.

@madiodio
Last active October 31, 2020 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madiodio/5ae9ea59775a4de8ad2a5e3321a76418 to your computer and use it in GitHub Desktop.
Save madiodio/5ae9ea59775a4de8ad2a5e3321a76418 to your computer and use it in GitHub Desktop.
let A = [
{ _id: "34231555", status: "CANCELED", motif: "unable" },
{ _id: "1234551", status: "FAILLED", motif: "no number" },
,
{ _id: "1234455", status: "CANCELED", motif: "injoignable" },
];
let B = ["34231555", "1234455"];
// First, we filter only ids we want to update!
let filteredItemIds = A.filter(item => B.includes(item._id))
// Now update status and motifs based , C will the result of the update so the new reference you will need to use instead of A
let C = filteredItemIds.map(item => {
item.status = "DELETED"
item.motif = "Just deleted"
return item;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment