getting map with .includes(values of ARRAY)

So I am trying to map my routes based on what roles they have. For instance my map routes.roles:["User","Admin"] or just ["Admin"]. And Current user has one or multiple roles. This works

let newRoutes = testRoutes.filter(route => {
      return route.roles.includes("Admin");
    });

but i need it instead of "Admin" to compare to each Value in currentUser.Roles, which is an array of string. Please Help!!

1 answer

  • answered 2019-11-14 04:28 Vahid Akhtar

    You can filter single or multiple roles using filter()

    Example -

    let roles = ["User","Admin", "User2", "Admin2", "Manager"];
    let res = roles.filter(role=>role==='Admin'?role:role==='User'?role:role==='Manager'?role:'')
    console.log(res)