Updated Answer:
Comma-delimited numbers are language-specific and not all uses this system.
There are many wrong/incomplete answers on Stackoverflow, which are tailored for a specific local, or suggesting a 3rd-party script from NPM, which I believe to be an overkill.
Here's a list of not-good-at-all answers:
- How do I convert String to Number according to locale (opposite of .toLocaleString)?
- Is there any JavaScript standard API to parse to number according to locale?
There is one particular good answer which addresses multiple locales:
https://stackoverflow.com/a/45309230/104380
Previous Answer:
Converts comma delimited number string into a type number (aka type casting)
+"1,234".split(',').join('') // outputs 1234
Breakdown:
+ - math operation which casts the type of the outcome into type Number
"1,234" - Our string, which represents a comma delimited number
.split(',') - split the string into an Array: ["1", "234"], between every "," character
.join('') - joins the Array back, without any delimiter: "1234"
And a simple function would be:
function stringToNumber(s){
return +s.split(',').join('');
}