Your "array" as shown is invalid JavaScript syntax. Curly brackets {}
are for objects with property name/value pairs, but square brackets []
are for arrays - like so:
someArray = [{name:"Kristian", lines:"2,5,10"}, {name:"John", lines:"1,19,26,96"}];
In that case, you can use the .splice()
method to remove an item. To remove the first item (index 0), say:
someArray.splice(0,1);
// someArray = [{name:"John", lines:"1,19,26,96"}];
If you don't know the index but want to search through the array to find the item with name "Kristian" to remove you could to this:
for (var i =0; i < someArray.length; i++)
if (someArray[i].name === "Kristian") {
someArray.splice(i,1);
break;
}
EDIT: I just noticed your question is tagged with "jQuery", so you could try the $.grep()
method:
someArray = $.grep(someArray,
function(o,i) { return o.name === "Kristian"; },
true);
0
Created by nnnnnn on 2020-03-11 19:56:10 +0000 UTC
Share