How to get the last part of a URL after the last slash (/) in JavaScript

1 Answer

0 votes
const url = "http://www.website.com/abc/xyz";

const s = url.slice(url.lastIndexOf('/') + 1, url.length);
 
document.write(s);
 

     
/*
run:
 
xyz 
          
*/

 



answered Feb 17, 2020 by avibootz

Related questions

1 answer 213 views
2 answers 303 views
2 answers 241 views
3 answers 823 views
1 answer 210 views
1 answer 189 views
...