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