How to get the value of a string after last slash in Node.js

2 Answers

0 votes
const str = '/development/avibootz.com/src/nodejs';

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

console.log(last_sub_str);

  
  
  
  
/*
run:
  
nodejs
  
*/

 



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

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

console.log(last_sub_str);

  
  
  
  
/*
run:
  
nodejs
  
*/

 



answered Jul 9, 2022 by avibootz

Related questions

2 answers 251 views
2 answers 283 views
1 answer 210 views
1 answer 340 views
2 answers 445 views
2 answers 398 views
...