how to trim spaces from a string in javascript using .trim code example Example: remove whitespace javascript var str = " Some text "; str.trim();