Reversing an Object.entries conversion

后端 未结 5 1645
一个人的身影
一个人的身影 2020-12-17 10:03

I am using Object.entries in order to get some values out of a nested object and filter it.

obj = Object.entries(obj)
  .filter(([k, v]) => {         


        
5条回答
  •  青春惊慌失措
    2020-12-17 10:52

    If you know exactly which entries you want to exclude, you can use object deconstruction combined with spreading:

    function clean(obj) {
      const { unwanted1, unwanted2, ...wanted } = obj;
      return { ...wanted };
    }
    

    For some cases, this might be the cleanest solution.

提交回复
热议问题