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
What is HTML? HTML is a language used to describe...
Copy code The code is as follows: <style> ....
Preface: With the continuous development of Inter...
Effect check address: Tour plan (uplanok.com) Cod...
Transactions ensure the atomicity of multiple SQL...
1. Create a user: Order: CREATE USER 'usernam...
When installing the centos7 version, choose to co...
Let me first explain why the text is not vertical...
The reason is that all files are encoded in utf8. ...
Generally speaking, after the container is starte...
Table of contents 1. Install node 2. Install Comm...
Table of contents 1. What is a component? 2. Crea...
REPLACE Syntax REPLACE(String,from_str,to_str) Th...
In the past few days, the website has been access...
Table of contents 1. List traversal 2. The role o...