1. Set Deduplicationfunction funSet(arr){ return Array.from(new Set(arr)); } 2. Double for loop to remove duplicatesfunction funFor(arr){ for(let i=0,len=arr.length;i<len;i++){ for(let j=i+1,len=arr.length;j<len;j++){ if (arr[i]===arr[j]){ arr.splice(j,1); len--; j--; } } } return arr; } 3. Use indexOf to remove duplicatesfunction funIndex(arr){ let newArr = []; for(let i=0;i<arr.length;i++){ if (newArr.indexOf(arr[i])===-1){ newArr.push(arr[i]) } } return newArr; } 4. Use icludes to remove duplicatesfunction funInclude(arr){ let newArr = []; for(let i=0;i<arr.length;i++){ if (!newArr.includes(arr[i])){ newArr.push(arr[i]) } } return newArr; } 5. Filterfunction funFilter(arr){ return arr.filter(function(item,index){ return arr.indexOf(item,0)===index; }) } 6. Mapfunction funMap(arr){ let map = new Map(); let newArr = []; for(let i=0,len=arr.length;i<len;i++){ if (map.has(arr[i])){ map.set(arr[i],true); }else{ map.set(arr[i],false); newArr.push(arr[i]); } } return newArr; } SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to realize vertical arrangement of text using CSS3
>>: Several practical scenarios for implementing the replace function in MySQL
Table of contents Stabilization Introduction Anti...
Table of contents 1. Enter the network card confi...
1. Brief introduction of the event An event is a ...
1. Download the MySQL 5.7.11 zip installation pac...
How to turn a jar package into a docker container...
Author: Ding Yi Source: https://chengxuzhixin.com...
Zero, Background I received a lot of alerts this ...
Preface I believe that the syntax of MySQL is not...
When doing a project, it is inevitable to encount...
After MySQL is installed, you can verify whether ...
This article records the detailed process of down...
Table of contents SQL execution order bin log Wha...
1. The effect diagram implemented in this article...
1. flex-grow, flex-shrink, flex-basis properties ...
The installation tutorial of mysql5.7.17 is share...