<script> var arr=["1","2","3","2","4","3"]; var res=unique(arr); console.log(res); // 数组去重 function unique(arr){ var arr2 = arr.sort(); var res = [arr2[0]]; for(var i=1;i<arr2.length;i++){ if(arr2[i] !== res[res.length-1]){ res.push(arr2[i]); } } return res; } </script>
文章评论(0)