I have an object. I want to get the keys if the value is true.
What I have tried :
const data = [{superadmin: true, admin: false, user: false}]
keys = Object.keys(data).filter(k => data[k]);
console.log(typeof(data));
console.log(data)
console.log(keys)
Expected Output :
["superadmin"]
>Solution :
This works
const data = [{
superadmin: true,
admin: false,
user: false
}]
keys = data.map(obj => {
const data = Object.keys(obj).filter((key) => {
return !!obj[key]
})
return data
}).flat(1);
console.log(keys)