In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of what js six array deduplication methods are, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this js six array deduplication methods. Let's take a look at it.
The first new Set
Var fun = function (arr) {
Return [... New Set (arr)]
}
The second kind of new Map
Var fun = function (arr) {
Let map = new Map ()
Let res = []
For (let I = 0; I
< arr.length; i++) { if (!map.has(arr[i])) { map.set(arr[i], i); res.push(arr[i]); } } return arr; }; 第三种 两层for循环+splice var fun = function (arr) { let len = arr.length; let res = []; for (let i = 0; i < len; i++) { for (let j = i + 1; j < len; j++) { if (arr[i] === arr[j]) { arr.splice(j, 1); len--; j--; i--; } } } return arr; }; 第四种 indexOf var fun = function (arr) { let res = []; for (let i = 0; i < arr.length; i++) { if(res.indexOf(arr[i])==-1) { res.push(arr[i]) } } return res }; 第五种 includes var fun = function (arr) { let res = []; for (let i = 0; i < arr.length; i++) { if (!res.includes(arr[i])) { res.push(arr[i]) } } return res }; 第六种 filter var fun = function (arr) { return arr.filter((item, index) =>{
Return arr.indexOf (item) = = index
})
}
This is the end of the article on "what are the methods of removing duplicates in js six arrays?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the methods of removing weight in js six arrays". If you still want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.