There are quite a few of new features has been added in the ECMAScript 5. I thought to introducing article series describing one feature in each series.
This article describes indexOf feature of Array in ECMAScript 5.
Array.indexOf()
Signature
array.indexOf(searchElement[, startIndex])
searchElement - Search the value in the array
startIndex - Specifies the starting index of search.This is optional argument, by default startIndex is 0.
Returns
The index of the search element in the array. It returns 0 if the search element is not found.
Example
var arr = [87, 122, 504, 9, 7, 30, 31, 76, 87, 2];
arr.indexOf('122') Output: 1
arr.indexOf('65') Output: -1
arr.indexOf('122',2) Output: -1
This ends the first series of ECMAScript 5.
|