Skip to content

Instantly share code, notes, and snippets.

@Kcko
Forked from scottopolis/splice-object-array.js
Last active August 8, 2022 14:01
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 Kcko/290c7c1a188b8dc94e786adcf1c06cd3 to your computer and use it in GitHub Desktop.
Save Kcko/290c7c1a188b8dc94e786adcf1c06cd3 to your computer and use it in GitHub Desktop.
Remove object from array of objects in Javascript
// source: http://stackoverflow.com/questions/16491758/remove-objects-from-array-by-object-property
// we have an array of objects, we want to remove one object using only the id property
var apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
// get index of object with id:37
var removeIndex = apps.map(function(item) { return item.id; }).indexOf(37);
// remove object
apps.splice(removeIndex, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment