String.prototype.indexOf() | javascript substring indexof
TheindexOf()methodreturnstheindexwithinthecallingString[1]objectofthefirstoccurrenceofthespecifiedvalue,startingthesearchatfromIndex.Returns-1ifthevalueisnotfound.ThesourceforthisinteractiveexampleisstoredinaGitHubrepository.Ifyoudliketocontributetotheinteractiveexamplesproject,pleaseclonehttps://github.com/mdn/interactive-examples[2]andsendusapullrequest.Syntaxstr.indexOf(searchValue[,fromIndex])ParameterssearchValueThestringvaluetosearchfor.Ifnostringisexplicitlyprovided,searchValuewillbec...
The indexOf() method returns the index within the calling String[1] object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
The source for this interactive example is stored in a GitHub repository. If youd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples[2] and send us a pull request. Syntax str.indexOf(searchValue [, fromIndex]) Parameters searchValueThe string value to search for.
If no string is explicitly provided, searchValue will be coerced to "undefined"[3], and this value will be searched for in str.
So, for example: undefined.indexOf() will return 0, as undefined is found at position 0 in the string undefined. undefine.indexOf() however will return -1, as undefined is not found in the string undefine.
fromIndex OptionalAn integer representing the index at which to start the search. Defau...