javascript replace all characters with another code example
Example 1: replace all occurrences of a string in javascript
const p = 'dog dog cat rat';
const regex = /dog/gi;
console.log(p.replace(regex, 'cow'));
Example 2: replace all js
let a = 'a a a a aaaa aa a a';
a.replace(/aa/g, 'bb');
Example 3: replace all character in string javascript
let a = "How to search and replace a char in a string";
while (a.search(" ", ""))
{
a = a.replace(" ", "");
}
console.log(a);
Example 4: how to replace all characters in a string javascript
const string = "a, b, c, d, e, f";
string.replace(/,/g, '');
console.log(string)