0

I have the method below that takes an array of strings. I want to be able to return true if the user has any of the array string passed.

How can I achieve that?

      const hasAnyPermission = (permissionsPassed: string[]) => {
        if (user?.permissionsEnabled === false) {
          return true
        }

        //permissions below is an array of strings
        return permissions.includes(permissionsPassed)
      }
2
  • Does this answer your question? how to tell if an array includes any of the substrings Commented Sep 2, 2020 at 20:22
  • there's no other way but to traverse the array. I recommend to use either a Map or a Set to check if it includes permissionPassed. code would be like so : permissionsPassed.some(permission => permissions.has(permission)) Commented Sep 2, 2020 at 21:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.