DEV Community

loading...

Discussion on: Why does indexOf output like this?

Collapse
mohsenalyafei profile image
Mohsen Alyafei • Edited
  1. Always remember that the search is always in a forward direction.

  2. The negative index tells where the starting position to search; it does not mean search backwards.

  3. You asked it to start searching from position -1 which is from the number 41 going forward. So there is nothing.