Array.prototype.indexOf () - JavaScript | MDN
Jul 10, 2025 · The indexOf() method of Array instances returns the first index at which a given element can be found in the array, or -1 if it is not present.
Searching…
Jul 10, 2025 · The indexOf() method of Array instances returns the first index at which a given element can be found in the array, or -1 if it is not present.
Description The indexOf() method returns the position of the first occurrence of a value in a string. The indexOf() method returns -1 if the value is not found. The indexOf() method is case sensitive.
The indexOf() returns the index of the first occurrence of a substring in a string, or -1 if the string does not contain the substring. The indexOf() always performs a case-sensitive search.
indexOf () Return Value Returns the first index of the element in the array if it is present at least once. Returns -1 if the element is not found in the array. Note: indexOf() compares searchElement to elements of th...
Jul 8, 2025 · Learn how to use indexOf () in JavaScript with syntax, examples, best practices, and comparisons with includes (). Perfect for beginners. Tagged with javascript, webdev, beginners, programming.
Sep 27, 2024 · The indexOf () method in JavaScript is used to find the position of the first occurrence of a specific value in an array. If the value is not present, it returns -1.
indexOf() can be incredibly useful for quickly checking for the presence of an element on an array. We have defined a function, quickCheck, that takes an array and an element as arguments.