Linked Questions

Popular Questions

How to sum jquery map values

Asked by At

I have map function to get selected checkboxes and I need to sum values of this map but I get NaN

Code

var prices = $("input:checkbox:checked").map(function(){
  return $(this).val();
}).get();


var number = prices;
var nf = new Intl.NumberFormat('en-US', {
  maximumFractionDigits:0, 
  minimumFractionDigits:0
});
var formattedNumber = nf.format(number);

$('.paybutton').append('<a class=" btn-link" href="">'+ nf.format(prices)+'</a>');

console.log(prices); returns data below when i play with check boxes so i guess my map is OK.

Array [ "5467457" ]
Array [ "57558", "5467457" ]
Array [ "57558" ]
Array []

In other hand my appended data is like:

5,467,457NaN57,55805,467,4570

And it keeps this way as long as i play with check boxes.

Question

  1. How can I have sum of my function in + nf.format(prices)+?

Related Questions