I have an array, I want to filter out all the paths which are in form of /__/:__Id
. I am currently using .endsWith
property but I want to make a generic code which recognizes the pattern and doesn't return paths in pattern of /routename**/:nameId**
const ROUTES = [ { path: "/" }, { path: "/faqs" }, { path: "/contactus" }, { path: "/pricing" }, { path: "/products" }, { path: "/careers/:jobId" }, { path: "/careers" }, { path: "/about-us" }, { path: "/features" }, { path: "/usecase/:usecaseId" } ];
const selectedRoutes = ROUTES.map( (item) => {
if (item.path === "/")
return "";
else
return item.path;
}).filter( (item) => { return !item.endsWith("Id")});
console.log(selectedRoutes)
I want to filter out all the paths which are in form of /__/:__Id
and thendoesn't return paths in pattern of /routename**/:nameId**
- these two statements seem to contradict each other - or I am misunderstand you. In any case; clarification would help :)