In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "es6 how to determine whether the array is duplicated", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "es6 how to determine whether the array is repeated" bar!
Judgment method: 1, use the length attribute to obtain the length of the original array; 2, use "[... new Set (arr)]" to remove the repeated elements in the array and return a new array; 3, use the length attribute to obtain the length of the array after deduplication; 4, use the "= =" to compare whether the length of the array obtained twice is equal, if equal, the array is not repeated.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
Es6's method of judging whether an array is duplicated or not
Realize the idea:
Using length attribute to get the length of the original array
Use [... new Set (arr)] to remove repeating elements from the array.
Using the length attribute to get the length of the array after being deduplicated
Using the = = operator to compare, whether the length of the array obtained twice is equal, and if so, the array is not repeated.
Implementation code:
Var arr = [1Jing 2 Jing 3 Jing 3 Jing 4 Jue 5]; len1=arr.length;newArr= [... new Set (arr)]; len2=newArr.length;if (len1==len2) {console.log ("array does not repeat");} else {}
As you can see, the array in the above example is duplicated.
Var arr = [1Jing 2Jing 3Jing 4Jing 5]; len1=arr.length;newArr= [. New Set (arr)]; len2=newArr.length;if (len1==len2) {console.log ("array does not repeat");} else {}
As you can see, the array in the above example is not duplicated.
Thank you for your reading, the above is the content of "how es6 determines whether the array is duplicated". After the study of this article, I believe you have a deeper understanding of how to judge whether the array is repeated by es6, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.