indexOf and lastIndexOf in JavaScript Arrays

Опубликовано: 14 Март 2026
на канале: Struct Feed
699
9

In this video I go over the indexOf and lastIndexOf functions in javascript arrays.

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

arr.indexOf(searchElement);
arr.indexOf(searchElement,startIndex);

It compares items using strict equality (===), so it will look for data type to be same as well

lastIndexOf method also works same way except it will search the array from back to the front