How to use the str.replaceAll() method In Javascript
In this example, we will see the use of the JavaScript str.replaceAll() method for replacing multiple strings.
Example: This example shows the implementation of the above-explained appraoch.
const str = 'who.where_when-how';
const result = str
.replaceAll('.', '?')
.replaceAll('_', '?')
.replaceAll('-', '?');
console.log(result);
Output
who?where?when?how
Replace multiple strings with multiple other strings in JavaScript
In this article, we are given a Sentence having multiple strings. The task is to replace multiple strings with new strings simultaneously instead of doing it one by one, using JavaScript.
Below are a few methods to understand:
Table of Content
- Using JavaScript replace() method
- Using the JavaScript str.replaceAll() method
- Using Array.reduce() method: