The case is simple - I've got a following object:
Object {1: false, 2: true, 3: false, 4: false, 5: false, 6: false, 7: false, 8: true, 12: false, 13: false, 14: false, 15: false, 16: false, 17: false, 18: false, 19: false}
and I need to get an array of ids that had true value, using underscore. In above case that would be:
[2, 8]
I tried few things but I'm a bit stuck. Does anyone have any idea?
you can use reduce:
or chain map:
Another potential solution:
So basically:
My version:
Giorgi Kandelaki gave a good answer, but it had some potential problems (see my comment on his answer).
The correct way is:
or
I use this one: Retrieve all keys with the same value from an object (not only an object with just boolean values) using
lodash
Example: