js replace from string code example
Example 1: javascript replace string
var str = "JavaScript replace method test";
var res = str.replace("test", "success");
Example 2: replace all js
let a = 'a a a a aaaa aa a a';
a.replace(/aa/g, 'bb');
Example 3: str replace javascript all
str.replace(/abc/g, '');
Example 4: replace in string javascript
const p = 'hello world ! hello everyone ! ';
const regex = /hello/gi;
console.log(p.replace(regex, 'good morning'));
console.log(p.replace('hello', 'good evening'));