Created
November 28, 2022 17:39
-
-
Save RayanAbid/0ec710fe78e94dbf1905d1e11291acbe to your computer and use it in GitHub Desktop.
Removes a specific index from an array of objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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