Second argument to indexOf is the starting offset. Negative offsets start from the end of the array. Also if an element is not found -1 is returned. So if you start at the last element (-1th?) There is only 41 so 16 is not an element hence returning -1. If you start from the second to last element your search array is [16, 41] which does have 16 so it outputs the position in the overall array of that element (i.e. 6th position).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Second argument to
indexOf
is the starting offset. Negative offsets start from the end of the array. Also if an element is not found -1 is returned. So if you start at the last element (-1th?) There is only 41 so 16 is not an element hence returning -1. If you start from the second to last element your search array is [16, 41] which does have 16 so it outputs the position in the overall array of that element (i.e. 6th position).