JavaScriptStringindexOf

Returns the index of the first occurrence of a specified value.

Syntax

str.indexOf(searchStr, fromIndex?)

Example

Enter values below to update the example in real time.

const
arr
console
indexOf
const arr = [10, 20, 30, 20];
console.log(arr.indexOf(20));    // 1
console.log(arr.indexOf(20, 2)); // 3