Using js remove comma from number from existing data
本问题已经有最佳答案,请猛点这里访问。
数组数据是
1 2 3 4 5 6 7 8 9 10 | [{ "Date":"2018-03-20", "Total":"10,459" }, { "Date":"2018-03-21", "Total":"11,947" }, { "Date":"2018-03-22", "Total":"12,932", }]; |
我需要像这样:
1 2 3 4 5 6 7 8 9 10 | [{ "Date":"2018-03-20", "Total":"10459" }, { "Date":"2018-03-21", "Total":"11947" }, { "Date":"2018-03-22", "Total":"12932", }]; |
号
使用jquery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var data=[{ "Date":"2018-03-20", "Total":"10,459" }, { "Date":"2018-03-21", "Total":"11,947" }, { "Date":"2018-03-22", "Total":"12,932", }]; $.each(data,function(index,item){ item.Total=item.Total.replace(",",""); console.log(item); }); |
。
1 | <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> |
使用
您可以使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | let data = [{ "Date":"2018-03-20", "Total":"10,459" }, { "Date":"2018-03-21", "Total":"11,947" }, { "Date":"2018-03-22", "Total":"12,932", }]; let res = data.map(elem => { elem.Total = elem.Total.replace(',', ''); return elem; }) console.log(res); |
简单的解决方案是使用parsefloat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | const data = [{ "Date":"2018-03-20", "Total":"10,459" }, { "Date":"2018-03-21", "Total":"11,947" }, { "Date":"2018-03-22", "Total":"12,932", }]; data.map(row => { row.Total = parseFloat(row.Total.replace(/,/g, '')); }) |
号
You can use
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | const x = [{ "Date":"2018-03-20", "Total":"10,459" }, { "Date":"2018-03-21", "Total":"11,947" }, { "Date":"2018-03-22", "Total":"12,932", }]; const y = x.map(el => { el.Total = el.Total.replace(/,/g,""); return el; }) console.log(y); |
使用
[cc lang="javascript"]var data = [{"Date":"2018-03-20","Total":"10,459