How to remove whitespace from both start and ends of a string in JavaScript

1 Answer

0 votes
let s = "          JavaScript Java C PHP          ";
 
s = s.trim()
 
console.log(s);


 
/*
run:
 
JavaScript Java C PHP
 
*/

 



answered Apr 12, 2017 by avibootz
edited Nov 21, 2024 by avibootz
...