# Javascript Math.Max Problem - Returning NaN

While looping through some XML using JQuery I am constructing a grouping of numbers.   From those numbers I am trying to acquire which of the numbers is the largest.  For some reason, it is returning NaN when I use the Math.max function.  Each number is no larger than 6 digits at most.

JQuery Loop to Construct Grouping
``````var snewmileagegroup = 0;
\$(this).find('XMLChild').each(function(){
snewmileagegroup = snewmileagegroup + ',' + parseFloat(\$(this).find('Mileage').text());
});
``````

Result: 0,36000,48000,65000

Now I taking the resulting variable and apply the Math.max function to it expecting the return of 65,000.  Problem is that I am getting NaN returned back instead.
``````var nmg = Math.max(snewmileagegroup);
``````

My suspicion is that I am not creating the collection of numbers correctly by concatenating ','.  Any help will be greatly appreciated.
###### Who is Participating?

Author Commented:
I should have waited to post this as I solved the problem.  Instead of creating a grouping I created an array of numbers.  So the code looks like this now.

``````var snewmileagegroup = new Array();
var i = 0;
\$(this).find('XMLChild').each(function(){
snewmileagegroup[i] = parseFloat(\$(this).find('Mileage').text());
i=i+1;
});

var nmg = Math.max.apply(Math, snewmileagegroup);
``````
0

Commented:
I don't know if you can send any collection to the max function.

can you try by sending them seperately like max(a,b,c)
0

Author Commented:
I figured out the solution on my own and therefore I am posting the solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.