Set all Object keys to false

后端 未结 9 1501
执念已碎
执念已碎 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:26

    In case you are dealing with 'scope' variables, this might be a better solution.

    Object.keys(filter).reduce(function(accObj, parseObj) {
                    accObj[parseObj] = false;
                    return accObj;
                  }, {});
    

提交回复
热议问题