// 去除字符串首尾的全部空白
var str = ' Ruchee ';
console.log(str.trim(), str.trim().length);
// "Ruchee" 6
// 去除字符串左侧空白
str = ' Ruchee ';
console.log('"' + str.replace(/^\s*/, '') + '"', str.replace(/^\s*/, '').length);
console.log('"' + str.trimStart() + '"', str.trimStart().length); // ES6
// "Ruchee " 7
// 去除字符串右侧空白
str = ' Ruchee ';
console.log('"' + str.replace(/(\s*$)/g, '') + '"', str.replace(/(\s*$)/g, '').length);
console.log('"' + str.trimEnd() + '"', str.trimEnd().length); // ES6
// " Ruchee" 7