Set all Object keys to false

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

    hasOwnProperty must be used

    ```

    for(var i in your_object) {
      if (Object.hasOwnProperty.call(your_object, i)) {
        your_object[i] = false;
      }
    }
    

    ```

提交回复
热议问题