Valeriane
Valeriane

Reputation: 954

json remove element by value

I have a json object :

myJson = [
{"id":"001", "name":"AAA"},
{"id":"002", "name":"BBB"},
{"id":"003", "name":"CCC"},
{"id":"004", "name":"DDD"}
]

How I can remove an element by value of id?

thank for your helps

Upvotes: 1

Views: 4696

Answers (1)

silly
silly

Reputation: 7887

you can filter your array... as example: you want to remove every object with the id "003" use this:

myJson = myJson.filter(function(jsonObject) {
    return jsonObject.id != "003";
});

Upvotes: 5

Related Questions