Array.indexOf

indexOf — Returns the first position of the element with the given value.

Description

Array.indexOf([integer search, [integer offset]])

Parameters

Name Description Type Default Optional
search integer Yes
offset integer Yes

Return values

integer.

Examples

Example #1 – indexOf example
var array = [2, 4, 8, 4, 16, 4, 32]; console.log(array.indexOf()); // -1 console.log(array.indexOf(3)); // -1 console.log(array.indexOf(4)); // 1 console.log(array.indexOf(4, 2)); // 3

See also

  • Array.lastIndexOf()

External references