The question says it all; JS doesn\'t seem to have a native trim() method.
The answer to so many JavaScript questions: jQuery
$j.trim(string)
Note: the above assumes your jQuery has been setup with:
Which is far more sensible than "$", and far less verbose than typing "jQuery" every time.