I need to loop through a series of values from a json array. I can explicitly name the object I want to sum but when I pass it a string parameter it won't work.
My code below:
var tot = 0
var category = "arson_15"
for(var i = 0; i < dc_nbh.features.length; i++) {
tot = tot + Number(dc_map.features[i].properties.category);
}
console.log(tot);
This returns "NaN" but when I change it to the code below it summs the values correctly:
var tot = 0
for(var i = 0; i < dc_nbh.features.length; i++) {
tot = tot + Number(dc_map.features[i].properties.arson_15);
}
console.log(tot);
why can't I pass a string var to the loop?