javascript - json remove element by value - Stack Overflow
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";
});
最新文章
- 苹果安卓交锋:开放做强生态链
- 微信支付和支付宝口水战开打!
- How do I convert a saved tensorflow model to pytorch which is not compatible with ONNX? - Stack Overflow
- Upgrading apache spark core from 3.3.2 to >=3.4.4 results in stackoverflowerror in logging - Stack Overflow
- eslint - How to have 2 no-restricted-globals rules with different severity? - Stack Overflow
- AWS CloudFront occasionally does not send request to custom origin server - Stack Overflow
- powerbi - Keep Date Filter Active After Hiding Matrix-Based Calendar in Report Viewer - Stack Overflow
- amazon web services - Problem with eventbridge when scheduling a rule - Stack Overflow
- c# - IdentityServer4 and returning an error in response - Stack Overflow
- ESP32 Bluetooth - Is it possible to keep Provisioning Manager Bluetooth Up, After Provisioning Is Done? - Stack Overflow
- javascript - How to properly handle AES encryption in React Native and generate Random Key for AES encryption? - Stack Overflow
- datagrid - Mudblazor MudDatagrid SelectedItemChanged problem with ondblclick version 8.0.0-preview - Stack Overflow
- React Native Build Error on Windows: "EMFILE: too many open files" During `assembleRelease` - Stack Overflow
- javascript - onPointerOver and onPointerOut detect all child elements - Stack Overflow
- google sheets - shortest formula to get the last non zero value from column - Stack Overflow
- volttron - POSTMAN REST Call Results in RPC Timed Out: 5 Seconds - Stack Overflow
- oop - How can I link an object to another object in Java? - Stack Overflow