Searching in array.Now let’s cover methods that search in an array.
indexOf/lastIndexOf and includes.The… Please note that indexOf… The method arr.lastIndexOf is the same as indexOf, but looks for from right to left.… A minor, but noteworthy feature of includes is that it correctly handles NaN, unlike indexOf… To search among elements:
indexOf/lastIndexOf(item, pos) – look for item starting from position pos,
If we’re interested in all occurrences, we can run indexOf… There is a slight inconvenience with indexOf in the if test.… To look for a substring, use: indexOf, or includes/startsWith/endsWith for simple checks.