js how to delete an object within an array code example

Example 1: 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);

Example 2: how to delete object in array

let array = [1,2,3];
let item = array.indexOf(2)
let deleteCount = 1;
array.splice(item, deleteCount)