My code is functioning properly:
var roles = user.getRoles()
for (var i = 0; i < roles.length; i++){
if (Roles[i].getName()== ‘Admin’){
--this line is reached
}
}
Nevertheless, I am contemplating if there's a way to achieve a TRUE/FALSE result without using a for/if loop. Below is an alternative approach that is not yielding the desired outcome:
if (user.getRoles().getName().indexOf('Admin') >-1){
-program does not reach this line
}
An error is thrown: user.getRoles().getName is not a function
Upon printing out roles, the output is: UserRole@718816d, UserRole@1ae91200, UserRole@48baf10b, UserRole@777d6d90, UserRole@34ad99fb, UserRole@6606e47c, UserRole@79ab731e, UserRole@65269056, UserRole@3d9cbf48, UserRole@6ce88983, UserRole@4e792483, UserRole@1f8ca93a