Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: JS: Compare strings of an array with object fields

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


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: JS: Compare strings of an array with object fields

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×