javascript replace string
snippet in javascript

javascript replace string

user722

var str = "JavaScript replace method test";
var res = str.replace("test", "success");  
//res = Javscript replace method success

javascript replace

user9064

var res = str.replace("find", "replace");

replace i javascript

user5363

let startText = "Yes, I said yes, it is, yes."

// Replace with no modifiers
let newText = startText.replace("yes", "no")
console.log(newText)  // "Yes, I said no, it is, yes."

// Replace with 'g'-global modifier
newText = startText.replace(/yes/g, "no")
console.log(newText)  // "Yes, I said no, it is, no."

// Replace with modifiers 'g'-global and 'i'-case insensitive
newText = startText.replace(/yes/gi, "no")
console.log(newText)  // "no, I said no, it is, no."

replace javascript

user9998

var str = "Visit Microsoft!";

var res = str.replace("Microsoft", "W3Schools");

console.log(res);
/*Result
Visit W3Schools!
*/

replace string method js

user778


var str = "Mr Blue has a blue house and a blue car";

var res = str.replace(/blue/g, "red");
 

js string replace

user8883

var str = "Visit Websites!";

var res = str.replace("Websites", "Grepper");