标签云

微信群

扫码加入我们

WeChat QR Code

I have a json object as shown below. where i want to delete the "otherIndustry" entry and its value by using below code which doesn't worked.var updatedjsonobj = delete myjsonobj['otherIndustry'];How to remove Json object specific key and its value.Below is my example json object where i want to remove "otherIndustry" key and its value.var myjsonobj ={"employeeid": "160915848","firstName": "tet","lastName": "test","email": "[email protected]","country": "Brasil","currentIndustry": "aaaaaaaaaaaaa","otherIndustry": "aaaaaaaaaaaaa","currentOrganization": "test","salary": "1234567"};delete myjsonobj ['otherIndustry'];console.log(myjsonobj);where the log still prints the same object without removing 'otherIndustry' entry from the object.


Possible duplicate of Remove key-value pair from JSON object

2019年06月26日57分56秒

Your code should work, can you create a MVCE stackoverflow.com/help/mcve

2019年06月26日57分56秒

delete myObj.other.key1; As shown in this example.

2019年06月26日57分56秒

which doesn't worked What was the result? can you please explain?

2019年06月26日57分56秒

Nope Alexandru-IonutMihai, actually my code isvar myjsonobj ={"employeeid": "160915848", "firstName": "tet", "lastName": "test", "email": "testemail.com", "country": "Brasil", "currentIndustry": "aaaaaaaaaaaaa", "otherIndustry": "aaaaaaaaaaaaa", "currentOrganization": "test", "salary": "1234567" };delete myjsonobj ['otherIndustry'];console.log(myjsonobj ); still prints the same object. :(

2019年06月26日57分56秒

So irrespective of return value, will the key:value be deleted from object, as per OP's code?

2019年06月26日57分56秒