Delete multiple object properties?

后端 未结 9 985
天命终不由人
天命终不由人 2020-12-29 01:51

I create an object with multiple properties -

var objOpts = {
  option1: \'Option1\',
  option2: \'Option2\',
  option2: \'Option3\'
};

I t

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 02:19

    ES6 provides an elegant solution to this: Rest in Object Destructuring:

    let { a, b, ...rest } = { a: 10, b: 20, c: 30, d: 40 };
    console.log(rest); // { c: 30, d: 40 }
    

    Note that this doesn't mutate the original object, but some folks might still find this useful.

    Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

提交回复
热议问题