Reputation: 103
I've been looking through some js source and found someone using the indexOf() method. However, instead of passing a single parameter, they passed two like this:
string.indexOf(a,5)
where 'a' was a predefined string. What does this mean? Is it just indexing more than one parameter? Of so, what does it return?
Upvotes: 0
Views: 516
Reputation: 1248
Maybe this will help.
string.indexOf(searchvalue,start);
searchvalue = Required. The string to search for
start = Optional. Default 0. At which position to start the search
Upvotes: 0
Reputation: 187134
From MDN docs:
arr.indexOf(searchElement[, fromIndex = 0])
Where fromIndex
is defined as:
The index to start the search at. If the index is greater than or equal to the array's length, -1 is returned, which means the array will not be searched. If the provided index value is a negative number, it is taken as the offset from the end of the array. Note: if the provided index is negative, the array is still searched from front to back. If the calculated index is less than 0, then the whole array will be searched. Default: 0 (Entire array is searched).
So string.indexOf(a,5)
will look for a
in string
starting at the character with index 5
.
Upvotes: 1