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 123 views
1 answer 127 views
1 answer 110 views
1 answer 171 views
1 answer 102 views
1 answer 253 views
...