Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save heshamelmasry77/c27573bdd3f20536790882cb1efe8ee9 to your computer and use it in GitHub Desktop.

Select an option

Save heshamelmasry77/c27573bdd3f20536790882cb1efe8ee9 to your computer and use it in GitHub Desktop.

Revisions

  1. @scottopolis scottopolis created this gist Jan 24, 2017.
    10 changes: 10 additions & 0 deletions splice-object-array.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // 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);