How to use replaceAll() Method In Javascript
JavaScript replaceAll() method returns a new string after replacing all the matches of a string with a specified string or a regular expression. The original string is left unchanged after this operation.
Syntax:
const newString = originalString.replaceAll(regexp | substr , newSubstr | function)
Example: This example uses the replaceAll() method to replace ( ‘.’ ).
let str = "Geeks.for.Geeks";
let replacedStr = str.replaceAll(".", "");
console.log("Original string : " + str);
console.log("Modified string : " + replacedStr);
Output
Original string : Geeks.for.Geeks Modified string : w3wiki
How to replace all dots in a string using JavaScript ?
We will replace all dots in a string using JavaScript. There are multiple approaches to manipulating a string in JavaScript.
Table of Content
- Using JavaScript replace() Method
- Using JavaScript Split() and Join() Method
- Using JavaSccript reduce() Method and spread operator
- Using JavaScript replaceAll() Method
- Using JavaScript for loop
- Using JavaScript map() Method on Arrays