I want to replace all occurrences of white space characters (space, tab, newline) in JavaScript. How to do so?
I tried:
str.replace(/ /gi, \"X\
You could use the function trim
trim
let str = ' Hello World ';
alert (str.trim());
All the front and back spaces around Hello World would be removed.