es6语法:let str = ' a b c '; let arr = Array.from(new Set(str.split(''))).filter(val => val && val.trim()); str = arr.join('');