

Note: Index position always starts from 0. 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
Indexof javascript software#
Web development, programming languages, Software testing & others How does the indexOf() method work in JavaScript? Start Your Free Software Development Course
