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