Home > OS >  how get all value in pathname with url after first slash
how get all value in pathname with url after first slash

Time:11-18

resive pathname

pathname: "/kids/dlya-malyshey/platya-i-yubki"

using substr I will remove the first slash

location.pathname.substr(1,);

then i get

kids/dlya-malyshey/platya-i-yubki

and now the question is how can I take all the values ​​after the first slash? what would i get

dlya-malyshey/platya-i-yubki ???

CodePudding user response:

You've been on correct track. Just split your string by '/' sign and then take all except first.

const pathname = "/kids/dlya-malyshey/platya-i-yubki"
const pathnameParts = pathname.split("/").filter(Boolean);
console.log(pathnameParts);
const expectedResults = pathnameParts.slice(1).join("/")
console.log(expectedResults)
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related