In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
            
                    
                
2025-11-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you es6 and then judge whether the array has a certain value of the relevant knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.
Judgment method: 1, use the "arr.includes (element value)" statement, if the return value is true, then there is an item in the array; 2, use the "arr.findIndex ((v) = > {return value = element value;})" statement, if the return value is not "- 1", then the array contains an item.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
Es6 determines whether the array has a certain value.
Method 1: using includes () method
The includes () method is used to determine whether an array contains a specified value and returns true or false. Syntax:
Array.includes (searchElement, fromIndex)
SearchElement: the element to find
FromIndex: the index location to start the search, which can be omitted. The default value is 0.
Example:
Var arr= [2, 9, 7, 8, 9]; if (arr.indexOf (9)) {console.log ("specified value in array");} else {console.log ("no specified value in array");}
Method 2: using findIndex () method
The findIndex () method returns the index of the first element in the array that satisfies the provided test function. Otherwise,-1 is returned.
Var arr= [2, 9, 7, 8, 9]; var ret = arr.findIndex ((v) = > {return v = = 1;}); if (retorted return 1) {console.log ("specified value in the array");} else {console.log ("no specified value in the array");}
These are all the contents of the article "es6 and then determine whether the array has a certain value". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.

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.