I am trying to write a function that checks if a route is included in an array of routes:
const routes = ['/test', '/documentation/*']
function checkRoute(route) {
if (routes.includes(route)) {
console.log('Included!!')
} else {
console.log('Not included!')
}
}
The part I need help with is how to handle the wildcard *
- basically, I want any route that has the /docs/
prefix to be included such as:
/documentation/docs.json
, /documentation/index.html
Besides doing some very messy string manipulation, I am not sure how to achieve this. Any help would be greatly appreciated!