The question says it all; JS doesn\'t seem to have a native trim() method.
A slightly tinier version of @Pat's.
return str.replace( /^\s+|\s+$/g, '' );