In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use find () and findIndex () in ES6. It has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.
Find () and findIndex ()
The find method of the array instance, which is used to find the first qualified array member. Its argument is a callback function, which is executed by all array members in turn until the first member whose return value is true is found and then returned. If there are no eligible members, undefined is returned.
[1,4,-5,10] .find ((n) = > n)
< 0) // -5 [1, 5, 10, 15].find(function(value, index, arr) { return value >9;}) / / 10
In the above code, the callback function of the find method can take three parameters, in turn, the current value, the current position, and the original array. The use of the findIndex method of an array instance is very similar to the find method, returning the position of the first qualified array member, or-1 if none of the members match the condition.
[1,5,10,15] .findIndex (function (value, index, arr) {return value > 9;}) / / 2
Both methods accept the second parameter, which is used to bind the this object of the callback function.
In addition, both methods can find NaN, which makes up for the deficiency of the IndexOf method of the array.
[NaN] .indexOf (NaN) / /-1 [NaN] .findIndex (y = > Object.is (NaN, y)) / / 0 Thank you for reading this article carefully. I hope the article "how to use find () and findIndex () in ES6" shared by the editor will be helpful to you. At the same time, I hope you will support us, pay attention to the industry information channel, and more related knowledge is waiting for you 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.
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.