str.replace(/\s*/g, '');
str.replace(/^\s*|\s*$/g, '');
str.replace(/^\s*/g, '');
str.replace(/\s*$/g, '');
trim() 方法只能删除字符串两侧代码
str.trim();
let str = ' a b c ';
let arr = Array.from(new Set(str.split(''))).filter(val => val && val.trim());
str = arr.join('');
原文:https://www.cnblogs.com/cckui/p/11506786.html