- method 1
function trim(s) {
return s.replace(/^\s*|\s*$/g,"")
}
- method 2
// http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html
// Licensed under BSD
function myBestTrim(str) {
var start = -1, end = str.length; while (str.charCodeAt(--end)
while (str.charCodeAt(++start)
return str.slice(start, end + 1);
};