how to remove comma from end of string in javascript code example
Example 1: remove commas from string javascript
var stringWithCommas = 'a,b,c,d';
var stringWithoutCommas = stringWithCommas.replace(/,/g, '');
console.log(stringWithoutCommas);
Example 2: remove commas from string javascript
var purpose = "I, Just, want, a, quick, answer!";
var result = purpose.replace(",", "");
var result = purpose.replace(/,/g, "");
Example 3: remove last comma from string javascript
str = str.replace(/,\s*$/, "");