var str = "Visit Websites!"; var res = str.replace("Websites", "Grepper");
var str = "Original string!"; var str = str.replace("Original", "New");
str.replace(/abc/g, '');
str.replace(/hello/g, 'hi'); // the g is to show it's a global change, not one-time change. str.replace(new RegExp('hello', 'g'), 'hi');
let a = "How to search and replace a char in a string"; while (a.search(" ", "")) { a = a.replace(" ", ""); } console.log(a);