How to destructure an object based on a dynamic defined variable

后端 未结 2 503
独厮守ぢ
独厮守ぢ 2021-01-06 16:52

I am working with an immutable object that I need to add subtract an array of values from.

I know it\'s possible using ES6 destructing with the following.

         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 17:32

    arrayToRemove.reduce((obj, key) => {
      const { [key]: value, ...remainder } = obj
      return remainder
    }, originalObj)
    

提交回复
热议问题