Skip to content
loading...

re: Quick JavaScript Tip: the some() method VIEW POST

FULL DISCUSSION
 

It is quite handy!

I used .some() coupled with .includes() a while back to cross-reference two string arrays to make sure the user had at least one of the required roles for an action. The benefit of .some() here is that it will return true no matter how many of the iterations are false, as long as one of them is true.

//sample data
let userRoles = ['a','b','c','d'];
let validRoles = ['c','d','e','f'];
//end sample data

private isRoleValid(userRoles: string[], validRoles: string[]) {
    return userRoles && userRoles.some(e => validRoles.includes(e));
}
code of conduct - report abuse