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 287 views
2 answers 393 views
1 answer 266 views
1 answer 292 views
1 answer 214 views
...