Here is the problem. We have a currency value that is greater than
999. Some write such big currency values using comma separators.
It is a comparitively new string method. It was added to ECMAScript in ES2021. Using
replaceAll(), we can remove all commas like below:
const withCommas = "1,567,782.23"; const withoutCommas = withCommas.replaceAll(",", ""); console.log(withoutCommas); // "1567782.23"
replace() method is comparitively old and can be used with more confidence and platform support. It uses regular expression to find patterns and replace them.
const withCommas = "1,567,782.23"; const withoutCommas = withCommas.replace(/,/g, ""); console.log(withoutCommas); // "1567782.23"