I need to get an array with specific key values of an object.
Assume there is this object (optional some more different keys)
{
username: 'bla',
admin: true,
editor: true,
user: false,
foo: 'bar'
}
I only need to process the keys admin, editor and user and get those keys in an array, if their value is true. So in the example the result should be:
['admin', 'editor']
If all three keys have a false value, it should return an empty array.
I would do a filter first:
obj.filter(e => ['admin', 'editor', 'user'].indexOf(e) > -1 && !!e)
and then extract the keys?