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 117 views
1 answer 117 views
1 answer 101 views
1 answer 158 views
1 answer 94 views
1 answer 244 views
...