Return a string where "Microsoft" is replaced with "W3Schools":
The result of n will be:
The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.
Read more about regular expressions in our RegExp Tutorial and our RegExp Object Reference.
This method does not change the original string.
![]()
The replace() method is supported in all major browsers.
| Parameter | Description |
|---|---|
| searchvalue | Required. The value, or regular expression, that will be replaced by the new value |
| newvalue | Required. The value to replace the searchvalue with |
| Type | Description |
|---|---|
| String | A new string where the specified value(s) has been replaced by the new value |
| JavaScript Version: | 1.2 |
|---|
Perform a global replacement:
The result of n will be:
Perform a global, case-insensitive replacement:
The result of n will be:
JavaScript String Object
Your message has been sent to W3Schools.