JavaScript – Replace all commas in a string [duplicate]
The third parameter of String.prototype.replace() function was never defined as a standard, so most browsers simply do not implement it. The best way is to use regular expression with g (global) flag. var myStr=”this,is,a,test”; var newStr = myStr.replace(/,/g, ‘-‘); console.log( newStr ); // “this-is-a-test” Still have issues? It is important to note, that regular expressions … Read more