1var myStr = 'this,is,a,test';
2var newStr = myStr.replace(/,/g, '-');
3
4console.log( newStr ); // "this-is-a-test"
1var str = "JavaScript replace method test";
2var res = str.replace("test", "success");
3//res = Javscript replace method success
1let string = 'soandso, my name is soandso';
2
3let replaced = string.replace(/soandso/gi, 'Dylan');
4
5console.log(replaced); //Dylan, my name is Dylan