indexOf
Modified on Mon, 07 Aug 2023
Description
Get the index at which the first occurrence of value is found in array, else -1
Syntax
indexOf(array, value, fromIndex)
Parameters
Input Parameter | Type | Description |
---|---|---|
array | Array | The array to inspect |
value | any | The value to search for |
fromIndex (optional) | number | The index to search from |
Return value
Type |
---|
number |
Sample
Example | Result | Description |
---|---|---|
indexOf([1, 10, 1, 10], 10) | 1 | Search for the value 10 |
indexOf([1, 10, 1, 10], 10, 2) | 3 | Search for the value 10 from the index 2 |
indexOf([1, 2, 3, 4], 10) | -1 | Return -1 if the search value is not found |
To view all the List functions, click here.
See Also
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article