how to remove json object key and value.?

后端 未结 6 1452
忘了有多久
忘了有多久 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:33

    function omit(obj, key) {
        const {[key]:ignore, ...rest} = obj;
        return rest;
    }
    

    You can use ES6 spread operators like this. And to remove your key simply call

    const newJson = omit(myjsonobj, "otherIndustry");
    

    Its always better if you maintain pure function when you deal with type=object in javascript.

提交回复
热议问题