In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 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 the relevant knowledge points about the operation of indexOf and lastIndexOf in JavaScript. The content is detailed and the logic is clear. I believe 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.
Array.indexOf ()
The indexOf () method searches the array for element values and returns their positions.
Note: the location of the first project is 0, the location of the second project is 1, and so on.
Example
Retrieve the item "Apple" in the array:
Var fruits = ["Apple", "Orange", "Apple", "Mango"]
Var a = fruits.indexOf ("Apple")
Grammar
Array.indexOf (item, start)
Item is required. The item to retrieve.
Start is optional. Where to start the search. A negative value starts at the given position at the end and searches to the end.
If no item is found, Array.indexOf () returns-1.
If the project appears more than once, return to the location where it first appeared.
Array.lastIndexOf ()
Array.lastIndexOf () is similar to Array.indexOf (), but the search starts at the end of the array.
Example
Retrieve the item "Apple" in the array:
Var fruits = ["Apple", "Orange", "Apple", "Mango"]
Var a = fruits.lastIndexOf ("Apple")
All browsers support Array.lastIndexOf (), except for Internet Explorer 8 or earlier:
Grammar
Array.lastIndexOf (item, start)
Item is required. The item to retrieve.
Start is optional. Where to start the search. A negative value will start at the given position at the end and search to the beginning.
These are all the contents of this article entitled "how to operate indexOf and lastIndexOf in JavaScript". 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.
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.