js str.replace 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: javascript replace

var text = "Sentence with old text"
alert( text.replace("old text", "new text") ); // Sentence with new text

Example 3: javascript replace

var frase = "Son tres mil trescientos treinta y tres con nueve";
frase = frase.replace("tres","dos");
console.log(frase);
//Son dos mil trescientos treinta y tres con nueve

Tags: