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 138 views
2 answers 220 views
1 answer 123 views
1 answer 164 views
1 answer 121 views
1 answer 114 views
...