I am working on a function where I need to check if any of the role names, passed in as a string with or without pipe separation, exist within an existing JavaScript array.
While .includes
works well for single names, it doesn't work perfectly when dealing with multiple pipe separated names. In this case, my function fails to return true even if one of the names matches an element in the array.
is(roleName) {
let roles = roleName.split('|')
return roles.forEach(role => {
return this.$page.auth.user.roles.includes(role)
})
}
Just so you know, this is a method used as a mixin for Vue.js.
Thank you!