Kyle.Belanger Kyle.Belanger - 3 months ago 25
Javascript Question

Check if any key values are false in an object

I'm looking for a simple solution to check if any key values are

in an object.

I have an object with several unique keys, however, they only contain boolean values (

var ob = { stack: true,
overflow: true,
website: true

I know that I can get the number of keys in an Object, with the following line:

Object.keys(ob).length // returns 3

Is there a built in method to check if any key value is false without having to loop through each key in the object?


You can use the Array.some method:

var hasFalseKeys = Object.keys(ob).some(k => !ob[k]);