How do i return true
if location.pathname
is found in of these strings is found in ES6?
JavaScript
x
15
15
1
const noActionMenuRoutes = [
2
'/master/employees',
3
'/employees/dashboard',
4
'/employees/requests',
5
'/projects/myprojects',
6
];
7
8
const noActionMenus = () => {
9
if (location.pathname.some(noActionMenuRoutes)) {
10
return true;
11
} else {
12
return false;
13
}
14
};
15
Advertisement
Answer
You can use Javascript array includes
or indexOf
function.
JavaScript
1
2
1
if (noActionMenuRoutes.some(route => location.pathname.includes(route)))
2
JavaScript
1
2
1
if (noActionMenuRoutes.some(route => location.pathname.indexOf(route) !== -1)
2