Search for "W3Schools":
The result of n will be:
The search() method searches a string for a specified value, or regular expression, and returns the position of the match.
This method returns -1 if no match is found.
Read more about regular expressions in our RegExp Tutorial and our RegExp Object Reference.
![]()
The search() method is supported in all major browsers.
| Parameter | Description |
|---|---|
| searchvalue | Required. The value, or regular expression, to search for. |
| Type | Description |
|---|---|
| Number | The position of the first occurance of the specified searchvalue |
| JavaScript Version: | 1.2 |
|---|
Perform a case-sensitive search:
The output of the code above will be:
Perform a case-insensitive search:
The output of the code above will be:
JavaScript String Object
Your message has been sent to W3Schools.