How to remove all whitespace from string in JavaScript

1 Answer

0 votes
let str = '   javascript\n      c++ \n      ';

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

console.log(str);

  
  
  
  
/*
run:
  
"javascriptc++"
  
*/

 



answered Jun 10, 2022 by avibootz

Related questions

1 answer 126 views
1 answer 153 views
1 answer 187 views
3 answers 298 views
...