I have an array of objects and I want to get the max prevalence value.
I try this code:
// max of selected vaccine
var ex = [{"name": "a", "prevalence": "NaN"},
{"name": "a", "prevalence": "5"},
{"name": "b", "prevalence": "0"},
{"name": "a", "prevalence": "NaN"},
{"name": "c", "prevalence": "100"},
{"name": "c", "prevalence": "20"},
{"name": "a", "prevalence": "3"}];
console.log('ex:', ex);
var maxPrevalence = d3.max(ex, function(d) {
if(!isNaN(d.prevalence)) {
return d.prevalence;
}
});
console.log('\nmaxPrevalence:', maxPrevalence);
<script src='https://d3js.org/d3.v5.js' charset='utf-8'></script>
But the result is 5 not 100.
I don't have to use a d3 function, even pure javascript is fine.