Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mmichealjroberts/005d3fd39853ea1564cda64d085f535c to your computer and use it in GitHub Desktop.
Save mmichealjroberts/005d3fd39853ea1564cda64d085f535c to your computer and use it in GitHub Desktop.
Remove Objects From Array By Object Property
// 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