Created
May 4, 2020 08:32
-
-
Save mmichealjroberts/005d3fd39853ea1564cda64d085f535c to your computer and use it in GitHub Desktop.
Remove Objects From Array By Object Property
This file contains 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
// Source: http://stackoverflow.com/questions/16491758/remove-objects-from-array-by-object-property | |
var arr = [ | |
{ | |
id: 1, | |
property: "Property", | |
}, | |
{ | |
id:2, | |
property: "Property", | |
} | |
]; | |
// Get the index of the Array for object with id corresponding to 2: | |
var removeIndex = arr.map((element) => { return item.id; }).indexOf(2); | |
// Remove Object from Array: | |
arr.splice(removeIndex, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment