js去除空格的方法

js去除空格的方法

/**
* 去除空格
*/
trim(str) {
var result;
console.log(str)
if(str){
result = str.replace(/(^\s+)|(\s+$)/g,"");
// result = str.replace(/\s/g,""); // 去除字符串全部空格
}
return result?result:'';
},
posted @ 2022-04-08 10:19  前端白雪  阅读(646)  评论(0编辑  收藏  举报