1const string = "a, b, c, d, e, f";
2string.replace(/,/g, '');
3console.log(string) //a b c d e f
1function replaceAll(str, find, replace) {
2 var escapedFind=find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
3 return str.replace(new RegExp(escapedFind, 'g'), replace);
4}
5//usage example
6var sentence="How many shots did Bill take last night? That Bill is so crazy!";
7var blameSusan=replaceAll(sentence,"Bill","Susan");
1let a = "How to search and replace a char in a string";
2while (a.search(" ", ""))
3{
4 a = a.replace(" ", "");
5}
6console.log(a);