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 ')+'----');
posted @ 2020-03-28 21:05  IT文艺女  阅读(215)  评论(0编辑  收藏  举报