How to get the substring before specific character in Node.js

1 Answer

0 votes
const str = 'javascript c++ c typescript node.js';
 
const ch = 'y'
 
const subs = str.substring(0, str.indexOf(ch));
 
console.log(subs);
 
   
   
   
   
/*
run:
   
javascript c++ c t
   
*/

 



answered Feb 18, 2022 by avibootz

Related questions

1 answer 212 views
1 answer 216 views
1 answer 192 views
1 answer 257 views
1 answer 180 views
1 answer 353 views
...