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 185 views
2 answers 284 views
1 answer 171 views
1 answer 208 views
1 answer 165 views
1 answer 161 views
...