9
I got the following array with a few items:
var arr = [
{id: 1, name: "Jon Snow"},
{id: 2, name: "Michael Scolfield"},
{id: 3, name: "Dexter Morgan"}
];
To add new item the method is used push
. Exactly this way:
arr.push({
id: 1,
name: "Jon Snow"
})
I realized that it is possible to remove using the method splice()
passing the index as parameter. See:
arr.splice(index,1);
But I need to delete an item from array passing as parameter the id
, which would be an object attribute. Example:
function removeItem(id){
//remover o objecto com id específico
}
How to delete an item from a array passing as your parameter id
? What would be the best way to do that?
I think there’s a mistake here, it didn’t suck! ^^
– viana
@acklay Oops! try again, forgot to remove a snippet when renaming.=)
– OnoSendai