JavaScript trim newline

str = str.replace(/^\s+|\s+$/g, '');
Friendly Hawk