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

2 Answers

0 votes
const str = '/development/seek4info.com/src/typescript';

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

console.log(last_sub_str);

  
  
  
  
/*
run:
  
"typescript" 
  
*/

 



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

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

console.log(last_sub_str);

  
  
  
  
/*
run:
  
"typescript" 
  
*/

 



answered Jul 9, 2022 by avibootz

Related questions

2 answers 144 views
2 answers 183 views
1 answer 127 views
1 answer 229 views
2 answers 322 views
2 answers 266 views
3 answers 891 views
...