Remove value from object without mutation

后端 未结 8 797
天涯浪人
天涯浪人 2020-12-07 18:50

What\'s a good and short way to remove a value from an object at a specific key without mutating the original object?

I\'d like to do something like:



        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 19:27

    With ES7 object destructuring:

    const myObject = {
      a: 1,
      b: 2,
      c: 3
    };
    const { a, ...noA } = myObject;
    console.log(noA); // => { b: 2, c: 3 }
    

提交回复
热议问题