javascript remove commas from string 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!";

// Removing the first occurrence of a comma
var result = purpose.replace(",", "");

// Removing all the commas
var result = purpose.replace(/,/g, "");

Example 3: remove commas and dollar sign from string js

parseFloat('$148,326.00'.replace(/\$|,/g, ''))

Example 4: javascript remove multiple commas from string

/[,\s]+|[,\s]+/g

var str= "your string here";
//this will be new string after replace
str = str.replace(/[,\s]+|[,\s]+/g, 'your string here');