How to use replaceAll() method In Javascript
Example: In this article, we will use the JavaScript replaceAll() methods to remove all the occurrences of given text from the input string.
// Function to remove text
function removeText() {
// Input string
let originalText = 'w3wiki';
// Implementing replaceAll with text to be removed
let newText = originalText.replaceAll('Geeks', '');
// Display output
console.log(newText);
}
// Function call
removeText();
Output
For
How to remove text from a string in JavaScript ?
We will have a string and we need to remove the given text from that string using JavaScript. We need to print the new string in the console.
These are the following methods to Remove Text from a String:
Table of Content
- Method 1: Using replace() method
- Method 2: Using replace() method with Regex
- Method 3: Using substr() method
- Method 4: Using replaceAll() method
- Method 5: Using split() and join() method