1.对数组遍历

  1. <script>
  2. var arr=[1,2,1,2,4,6];
  3. var res=[];
  4. arr.forEach(item=>{
  5. if(!res.includes(item)){
  6. res.push(item);
  7. }
  8. })
  9. console.log(res);
  10. </script>

set方法

  1. <script>
  2. var arr=[1,2,3,4,3,2];
  3. var s=new Set(arr);
  4. console.log(s);
  5. console.log([...s]);
  6. </script>