Web/JavaScript/Reference/Global objects/Symbol/replace
The Symbol.replace well-known symbol specifies the method that replaces matched substrings of a string. This function is called by the String.prototype.replace() method.
For more information, see RegExp.prototype[@@replace]() and String.prototype.replace().
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Property attributes of Symbol.replace
|
|
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | no |
Examples
Using Symbol.replace
class CustomReplacer {
constructor(value) {
this.value = value;
}
[Symbol.replace](string) {
return string.replace(this.value, '#!@?');
}
}
console.log('football'.replace(new CustomReplacer('foo')));
// expected output: "#!@?tball"
Specifications
| Specification |
|---|
| ECMAScript (ECMA-262)The definition of 'Symbol.replace' in that specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
replace
|
Chrome
Full support 50 |
Edge
Full support 79 |
Firefox
Full support 49 |
IE
No support No |
Opera
Full support 37 |
Safari
Full support 10 |
WebView Android
Full support 50 |
Chrome Android
Full support 50 |
Firefox Android
Full support 49 |
Opera Android
Full support 37 |
Safari iOS
Full support 10 |
Samsung Internet Android
Full support 5.0 |
nodejs
Full support 6.0.0 |
Legend
- Full support
- Full support
- No support
- No support
See also
Symbol.replace by Mozilla Contributors is licensed under CC-BY-SA 2.5.