javascript string repace code example
Example 1: javascript replace string
var str = "JavaScript replace method test";
var res = str.replace("test", "success");
//res = Javscript replace method success
Example 2: string replace javascript
let re = /apples/gi;
let str = "Apples are round, and apples are juicy.";
let newstr = str.replace(re, "oranges");
console.log(newstr)
output:
"oranges are round, and oranges are juicy."