trim in javascript to remove all spaces code example Example: remove whitespace javascript var str = " Some text "; str.trim();