Set all Object keys to false

后端 未结 9 1499
执念已碎
执念已碎 2021-01-03 19:50

Lets say I have an object

  filter: {
    \"ID\": false,
    \"Name\": true,
    \"Role\": false,
    \"Sector\": true,
    \"Code\": false
  }
9条回答
  •  鱼传尺愫
    2021-01-03 20:31

    With ES6 features one-liner without mutation:

    {
      ...Object.keys(filter).reduce((reduced, key) => ({ ...reduced, [key]: false }), {})
    }
    

提交回复
热议问题