user3142695:
There is an Object, which represents the role of an user:
const user = {
isEditor: false,
isAdmin: true,
isTranslator: false
}
I need to pass some elements to a function an check if any of this role has a true value in the user object.
result = hasPermission(user, ['editor', 'admin']) // true
result = hasPermission(user, ['editor', 'translator']) // false
I've some problems with that, as the roles are named a bit differently. I thought also about using _.some()
as I need to check for only one true value.
function hasPermission (user, roles) {
roles.forEach(role => {
user[role] // is not working as user keys named differently
})
}
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE