JavaScript: Array.prototype.indexOf

By Xah Lee. Date: . Last updated: .
arrayX.indexOf(value)
Return the index of first element that is value. Return -1 if not found. NaN is never found. To find NaN, use Array.prototype.includes.
arrayX.indexOf(value, start_index)
Search starts at start_index.
console.log( [3,4,5,6].indexOf(5) === 2);
console.log( ["b", 5, 6, "b"].indexOf ( "b", 1 ) === 3 );
console.log( [3,3].indexOf (3,-1) === 1 );
console.log( [NaN].indexOf ( NaN ) === -1);
console.log( [undefined].indexOf( undefined ) === 0);
// all true

JS Array Search

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Array

prototype