trim function javascript next line code example Example: javascript trim newline str = str.replace(/^\s+|\s+$/g, '');