javascript - json remove element by value - Stack Overflow

I have a json object :myJson = [{"id":"001", "name":"AAA"},{&

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

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

Share Improve this question edited Nov 15, 2012 at 9:41 Bakudan 19.5k9 gold badges55 silver badges75 bronze badges asked Nov 15, 2012 at 9:33 ValerianeValeriane 9543 gold badges17 silver badges39 bronze badges 2
  • 4 You don't have a JSON object, you have an object. More specifically, you have an array of objects. The answer that silly posted is the simplest solution to removing an item, or you can use a standard loop to go through the array until you find the matching item and then use .splice() to remove it. – nnnnnn Commented Nov 15, 2012 at 9:36
  • 1 right. But I parsed this object to JSON – Valeriane Commented Nov 15, 2012 at 11:17
Add a ment  | 

1 Answer 1

Reset to default 5

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";
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745670334a4639365.html

相关推荐

  • javascript - json remove element by value - Stack Overflow

    I have a json object :myJson = [{"id":"001", "name":"AAA"},{&

    21天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信