How to use replaceAll() method In Javascript
We are using replaceAll() method which takes two arguments. We are passing the character that need to be changed and the character that will take place instead of previous one, That’s how it will replace the character/string. It can also take regular expression and function as an argument.
Example: It describes how we can replace multiple characters in a string using the replaceAll() method
// Original string
let str = 'gppkforgppks_ns_hele';
// Replacing multiple character
let result = str
.replaceAll('p', 'e')
.replaceAll('_', ' ')
.replaceAll('n', 'i')
.replaceAll('l', 'r');
// Printing the result
console.log(result);
Output
geekforgeeks is here
JavaScript Program to Replace Multiple Characters in a String
We are going to learn how we can replace Multiple Characters in a String. We have to replace multiple characters in a string using the inbuilt function or any other method.
Table of Content
- Using replace() method
- Using replaceAll() method
- Using split() and join()
- Using regular expression
- Using reduce()
- Using Map() Method