![]() |
In JavaScript, a string is a sequence of characters represented with quotation marks. We are given a string and we need to replace all occurrences of a substring from the given string. Table of Content Using the replace() method with regular expression
Example: The below code will explain the use of replace() method with regular expression. Javascript
Output
Before replacement: GeeksforGEEKS After Replacement: GeeksforGeeks Using indexOf() and slice() methods
Example: The below code will explain the use of the indexOf() and slice() methods to replace all occurences of a substring. Javascript
Output
Before replacement: GeeksforGEEKS After Replacement: GeeksforGeeks Using replaceAll() method
Example: The below code is practical implementation of the above-discussed approach. Javascript
Output
Before replacement: GeeksforGEEKS After Replacement: GeeksforGeeks |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |