admin管理员组文章数量:1435859
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
1 Answer
Reset to default 5you 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";
});
本文标签: javascriptjson remove element by valueStack Overflow
版权声明:本文标题:javascript - json remove element by value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745670333a2669530.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论