I could not understand the following documentation of indexof()

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

can anyone help?

What is the problem? Starting from index 2 (like mentioned in the comment), means we start at camel, so the first bison after camel is at index 4.

by specifying a start index, you skip everything before the start index.

does (‘bison’, 2) means to look for the index starting from index no. 2?

given the comment at line 6 says: start from index 2, and the method signature:

arr.indexOf(searchElement[, fromIndex])

also says fromIndex, it seems very plausible what you say.

1 Like

Thanks for Your help. Got it. I also got one more from documentation that I could not understand.

is explained:

If the provided index value is a negative number, it is taken as the offset from the end of the array

what does that mean? fromIndex -1 starts searching where? Combined with the result, what indexes do you think are searched?

same for indexOf(2, -3), you get an outcome of zero, which means the element (2) is present at index 0, so where does this indexOf start searching?

I could tell you, but you need to learn to read documentation, take your time to understand it, ask yourself questions, see if you can figure out how a certain outcome is reached

1 Like

Thank You for the help.