Skip to content

Instantly share code, notes, and snippets.

@RayanAbid
Created November 28, 2022 17:39
Show Gist options
  • Save RayanAbid/0ec710fe78e94dbf1905d1e11291acbe to your computer and use it in GitHub Desktop.
Save RayanAbid/0ec710fe78e94dbf1905d1e11291acbe to your computer and use it in GitHub Desktop.
Removes a specific index from an array of objects
// Array
const arr = [{id: "1", name: "Toby"}, {id: "2", name: "John"} ]
//remove item
const itemToBeRemoved = { id: "1", name: "Toby" };
// Function to rem item
arr.splice(
arr.findIndex((a) => a.id === itemToBeRemoved._id),
1
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment