Remove value from object without mutation

后端 未结 8 793
天涯浪人
天涯浪人 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:10

    My issue with the accepted answer, from an ESLint rule standard, if you try to destructure:

        const { notNeeded, alsoNotNeeded, ...rest } = { ...ogObject };
    

    the 2 new variables, notNeeded and alsoNotNeeded may throw a warning or error depending on your setup since they are now unused. So why create new vars if unused?

    I think you need to use the delete function truly.

提交回复
热议问题