The above example we can see while we are accessing Cow from the array then prints 6 as the index position. Whereas if we pass not existed value to the indexOf() method, it will return -1. It will return the actual index position. Var indexOfBookNotExisted=searchIndex(book2) ĭocument.write(book1+" position is :"+indexOfBook+"") ĭocument.write(book2+" position is :"+indexOfBookNotExisted) Īs we can observe from the output we can clearly see if we pass existed items from an array is given to the indexOf() method. Searching the index of a book from an array (without mentioning a position): Below example, we do not specify any position within the indexOf() method so, the search starts at the 0 th. The examples of the following are given below: Example #1
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |