Return an object key only if value is true

Object.keys gets the keys from the object, then you can filter the keys based on the values

var obj = {1001: true, 1002: false};

var keys = Object.keys(obj);

var filtered = keys.filter(function(key) {
    return obj[key]
});

FIDDLE

Leave a Comment