我有一個json對象,如下所示。我想通過使用下面的代碼來刪除「otherIndustry」條目及其值。如何刪除json對象的鍵值。
var updatedjsonobj = delete myjsonobj['otherIndustry'];
如何刪除Json對象的特定鍵及其值。 下面是我的例子json對象,我想刪除「otherIndustry」鍵和它的值。
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);
在日誌仍然打印相同的對象,但不從對象otherIndustry「條目。
的[拔下JSON對象鍵值對]可能的複製(https://stackoverflow.com/questions/24770887/remove-key-value-pair-from-json-object) –
你的代碼應該可以工作,你可以創建一個MVCE https://stackoverflow.com/help/mcve – gurvinder372
刪除myObj.other.key1; [如此示例中所示](https://stackoverflow.com/questions/1219630/remove-a-json-attribute/1219633#1219633) –