In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how es6 compares whether the values of two arrays are equal". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how es6 compares the values of two arrays to see if they are equal.
Every () and some () can be compared in es6, with the syntax "s1.length===s2.length&&s1.every (a = > s2.some (b = > axiomorphb)) & & s2.every (_ b = > s1.some (_ a = > _ a)").
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
Es6 compares whether the values of the two arrays are equal (regardless of the order of the arrays)
Implementation code: (replace two arrays with your own)
Let listA = val;// currently selects let listB = this.plainOptions;// data let result = listA.length = listB.length & & listA.every (a = > listB.some (b = > a = = b) & & listB.every (_ b = > listA.some (_ a = > _ a = _ b)
Use method api:
1 、 every
The every () method is used to detect whether all elements of the array meet the specified criteria (provided by the function).
The every () method detects all the elements in the array using the specified function:
If an element is detected in the array that is not satisfied, the entire expression returns false, and the remaining elements are no longer detected.
Returns true if all elements meet the condition.
Note: every () does not detect the empty array, and every () does not change the original array.
Syntax:
Array.every (function (currentValue,index,arr), thisValue)
Parameter description:
2 、 some:
The some () method is used to detect whether the elements in the array meet the specified condition (provided by the function).
The some () method executes each element of the array in turn:
If one element satisfies the condition, the expression returns true, and the remaining elements are no longer detected.
If no element satisfies the condition, false is returned.
Note: some () does not detect the empty array, and some () does not change the original array.
Syntax:
Array.some (function (currentValue,index,arr), thisValue)
Parameter description:
At this point, I believe you have a deeper understanding of "how es6 compares whether the values of two arrays are equal". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.