js remove whitespace from start and end of string code example
Example 1: remove spaces in a string js
str.replace(/\s+/g, '')
Example 2: remove whitespace with regex javascript
return str.replace(/\s/g, '');
Example 3: remove whitespace javascript
var str = " Some text ";
str.trim();
Example 4: suppress spaces in front and in the end of a string javascript
var hello = ' Hello there! ';
// returns "Hello there!"
hello.trim();