/**
*
* @function trimAll 去除字符串中的所有空格
* @param {*} ele
* @returns
*/
export const trimAll = (ele) => {
if(typeof ele === 'string'){
return ele.split(/[\t\r\f\n\s]*/g).join('');
}else{
console.error(`${typeof ele} is not the expected type, but the string type is expected`)
}
}
//引入并使用
let str = "北京市 / 北京市 / 海淀区"
str = trimAll(str).split("/").join("")
console.log(str) //北京市北京市海淀区
12-06
109
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-07
3392
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-22
2250
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)