Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

locate and delete an object in an array

 // 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);
 
PREVIOUS NEXT
Tagged: #locate #delete #object #array
ADD COMMENT
Topic
Name
8+8 =