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 171 views
2 answers 271 views
1 answer 161 views
1 answer 200 views
1 answer 152 views
1 answer 148 views
...