How to remove all spaces from a string in JavaScript

2 Answers

0 votes
let s = "javascript  java c    c++ c#  php   python"
 
s = s.replace(/\s+/g,'').trim();
 
console.log(s); 
 
 
 
 
/*
run:
 
"javascriptjavacc++c#phppython"
 
*/

 



answered May 25, 2021 by avibootz
edited Jan 29, 2022 by avibootz
0 votes
let s = "javascript  java c    c++ c#  php   python"
 
s = s.split(' ').join('');
 
console.log(s); 
 
 
 
 
/*
run:
 
"javascriptjavacc++c#phppython"
 
*/

 



answered Jan 29, 2022 by avibootz

Related questions

1 answer 134 views
1 answer 142 views
1 answer 170 views
2 answers 139 views
...