trim()
方法删除字符串两端的空格:
let str=" www.02405.com ";
console.log(str.trim()); //www.02405.com
replace()
方法删除字符串中指定位置的空格:
let str = " www.02405 .com ";
//删除字符串左边的空格
console.log(str.replace(/^\s*/g, '')); //www.02405.com
//删除字符串右边空格
console.log(str.replace(/\s*$/g, '')); // www.02405 .com
//删除字符串中间空格
console.log(str.replace(/[ ]/g,'')); // www.02405.com
//删除字符串两端空格
console.log(str.replace(/^\s*|\s*$/g, '')); //www.02405 .com
//删除字符串全部端空格
console.log(str.replace(/\s+/g, '')); //www.02405.com