replacing characters in string javascript

JavaScript
var str = "JavaScript replace method test";
var res = str.replace("test", "success");  
//res = Javscript replace method successvar myStr = 'this,is,a,test';
var newStr = myStr.replace(/,/g, '-');

console.log( newStr );  // "this-is-a-test"let string = 'soandso, my name is soandso';

let replaced = string.replace(/soandso/gi, 'Dylan');

console.log(replaced); //Dylan, my name is Dylan
Source

Also in JavaScript: