C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Symbol.replace PropertyThe JavaScript Symbol.replace symbol determine the method that replaces the matched substring of a string. Syntax
[Symbol.replace](string). Parameters
String. Return valueA new string. Browser Support
Example 1
<script>
class Rep {
constructor(value) {
this.value = value;
}
[Symbol.replace](string) {
return `${string}`;
}
}
var r=new Rep("java");
document.writeln("Before: "+r.value);
document.writeln("After: "+"TheDeveloperBlog".replace(r.value));
</script>
Output: Before: java After: TheDeveloperBlog Example 2
<script>
class Rep {
constructor(value) {
this.value = value;
}
[Symbol.replace](string) {
return `${string}`;
}
}
var r=new Rep("TheDeveloperBlog");
document.writeln("Before: "+r.value);
document.writeln("After: "+r.value.toUpperCase().replace(r.value));
</script>
Output: Before: TheDeveloperBlog After: JAVATPOINT
Next TopicJavaScript Symbol
|