//去除重复数据 function filterRepeatStr(str) { var ar2 = str.split(","); ar2.sort();//先排序 var res = [ar2[0]]; for (var i = 1; i < ar2.length; i++) { if (ar2[i] !== res[res.length - 1]) { res.push(ar2[i]); } } return res.join(','); }
返回值也是用逗号隔开的数组[1,2,3,4]