My array looks like this:
var points = [{category: "Category A", correct: "0"},{category: "Category B", correct: "4"}];
I am trying to see which category has the highest number of correct. I started by using Math.max on my array map to determine which one is the highest value (which it returns 4.) But when I try to expand on that return it begins defaulting to NaN.
var res = Math.max.apply(Math,points.map(function(k){
return k.correct;
}));
o.correct in this instance will return 4.
What I've tried:
Switching my return to
k.category-> This returns "NaN"
Treating it as a function and storing both variables in the
Math.max, this will pull both values of the object, but it does it for both objects in the array.Math.max.apply(Math,points.map(function(k){ var highestCat = k.category; var highestCor = k.correct; alert(highestCat + highestCor); }));
Any ideas on what I could do to be able to store these as 2 separate variables I could reference later on?