how to remove json object key and value.?

后端 未结 6 1395
忘了有多久
忘了有多久 2021-02-01 02:02

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 updatedjsono         


        
6条回答
  •  感情败类
    2021-02-01 02:32

    I had issues with trying to delete a returned JSON object and found that it was actually a string. If you JSON.parse() before deleting you can be sure your key will get deleted.

    let obj;
    console.log(this.getBody()); // {"AED":3.6729,"AZN":1.69805,"BRL":4.0851}
    obj = this.getBody();
    delete obj["BRL"];
    console.log(obj) // {"AED":3.6729,"AZN":1.69805,"BRL":4.0851}
    obj = JSON.parse(this.getBody());
    delete obj["BRL"];
    console.log(obj) // {"AED":3.6729,"AZN":1.69805}
    

提交回复
热议问题