Can someone explain to me why my JavaScript function behaves this way? It loops through an array of 3 objects, returning true when meeting a condition in the if statement. However, it does not exit after the first true and continues looping, ultimately returning false at the end.
To work around this issue, I created a different variable and returned it at the conclusion of the function. But I am still wondering why it operates like this?
this.CheckRoles = function (authLevel) {
angular.forEach(currentUser.roles, function (role) {
if(role >= authLevel)
{
//The user has the required permissions
return true;
}
});
return false;
}