How to get the value of a string after last slash in JavaScript

2 Answers

0 votes
const str = '/development/workingframe.com/src/javascript';

const last_sub_str = str.substring(str.lastIndexOf('/') + 1);

console.log(last_sub_str);

  
  
  
  
/*
run:
  
"javascript"
  
*/

 



answered Jul 9, 2022 by avibootz
0 votes
const str = '/development/workingframe.com/src/javascript';

const last_sub_str = str.split('/').pop();

console.log(last_sub_str);

  
  
  
  
/*
run:
  
"javascript"
  
*/

 



answered Jul 9, 2022 by avibootz

Related questions

2 answers 270 views
2 answers 257 views
1 answer 216 views
1 answer 345 views
2 answers 447 views
...