Javascript - Removing commas from an array of string numbers
You can use number in same map
callback function, g
to remove all occurrence of ,
dataArr = [" 1,431,417 ", " 1,838,127 ", " 679,974 ", " 2,720,560 ", " 544,368 ", " 1,540,370 "]
let arrData = dataArr.map(e => Number(e.replace(/(,\s*)+/g, '').trim()));
console.log(arrData)
['1,234', '7,8,90,'].map(eachNo => {
return eachNo.split(',').join('')
});
Split() will split string where it will find ,(comma) and will return an array of strings.
join() will operate on array of strings.
There also seems to be a space in your array which would be giving NaN, Remove everything other than digits and maybe a dot.
Try this regex:
e.replace(/[^\d.]/g, '');