How To/
var trimmed = str.replace(/^\s+|\s+$/g, '');