js去除字符串的前后空格

function trim(str) {
  if (str && typeof str === "string") {
  return str.replace(/^s+/,"").replace(/s+$/,""); //去除前后空白符
}
}
console.log('---'+trim(' jjj jjj ')+'----'); // console.log('---'+trim(' jjj jjj ')+'----');
原文地址:https://www.cnblogs.com/itsmart/p/12589375.html