How to remove the last comma from the end of string in Node.js

2 Answers

0 votes
let str = 'node.js,c,c++,python,';
 
str = str.replace(/,*$/, '');
 
console.log(str); 
 
   
   
   
   
/*
run:
   
node.js,c,c++,python
   
*/

 



answered Apr 12, 2022 by avibootz
edited Jun 9, 2022 by avibootz
0 votes
let str = 'node.js,c,c++,python,';
 
if (str.endsWith(',')) {
    str = str.slice(0, -1);
}
 
console.log(str); 
 
   
   
   
   
/*
run:
   
node.js,c,c++,python
   
*/

 



answered Jun 9, 2022 by avibootz

Related questions

2 answers 168 views
1 answer 137 views
1 answer 190 views
1 answer 134 views
1 answer 189 views
1 answer 162 views
...