How to remove extra spaces from string in JavaScript

1 Answer

0 votes
let s = "javascript  java c    c++ c#  php   python"

s = s.replace(/\s+/g,' ').trim();

console.log(s); 




/*
run:

javascript java c c++ c# php python

*/

 



answered May 25, 2021 by avibootz

Related questions

1 answer 290 views
2 answers 396 views
1 answer 268 views
1 answer 295 views
1 answer 217 views
...