JS Tutorial
Javascript-HomeJavascript-IntroductionJavaScript-File-UseJavascript-Output-ExampleJavaScript CommentJavaScript VariableJavaScript OperatorJavaScript ConsoleJavaScript StringJavaScript string splitJavaScript string sliceJavascript trim whitespaceJavaScript string indexOf methodJavaScript string lastIndexOf method
JavaScript DateJavascript conditional statement JavaScript string indexOf Method
JavaScript String indexOf method search searchValue in string and return index of first character of searchValue in string.
if searchValue not exist in string then string indexOf method return -1
Syntax
string.indexOf(searchValue)
string.indexOf(searchValue,fromIndex)
Example

Parameter Details
Parameter | Description |
searchValue | searchValue is given string that you wan to search in string and find index of searchValue |
fromIndex | Optional - fromIndex decide the index to start searching of searchValue in string |
Technical Details
Return | indexOf method return index of first character of searchValue if searchValue exist in string otherwise return -1 |
Browser Support
Browser | |||||
Version | yes | yes | yes | yes | yes |
Tips - When searchValue(substring) present more than one time in string then indexOf method return index of first searchValue
Example

fromIndex optional parameter
formIndex is optional parameter . it decide the index to start search in string and return index of searchValue if searchValue exist between startIndex and endIndex(last index of string) otherwise return -1
Example

indexOf() method case-sensitive
indexOf() method search searchValue(substring) as a case-sensitive
Example
