javasscript remove spaces from a string code example Example: remove space from string javascript var str = " Hello World! "; alert(str.trim());