I am having some problem when trying to perform some calculation inside a for loop using JavaScript:
for (var j = 0; j < count; j++) {
var attributes;
if (latlng !== 'Null') {
attributes = results[j].feature.attributes;
}
var totalYC = parseInt(attributes["AGE_0_2"] + attributes["AGE_3_4"] + attributes["AGE_5_6"]);
var r = {
pa: attributes["Planning Area Name"],
sitearea: parseFloat(attributes["SHAPE_Area"] * 0.0001),
total_pop: parseInt(attributes["TOTAL_POPULATION"]),
scpr: parseInt(attributes["TOTAL_SCPR"]),
yc: parseInt(totalYC),
age_0_2: parseInt(attributes["AGE_0_2"]),
age_3_4: parseInt(attributes["AGE_3_4"]),
age_5_6: parseInt(attributes["AGE_5_6"]),
};
r_array.push(r);
}
I want my totalYC to sum up for the total of attributes["AGE_0_2"] + attributes["AGE_3_4"] + attributes["AGE_5_6"] just for once only. Let's say attributes["AGE_0_2"] is 1, attributes["AGE_3_4"] is 2 and attributes["AGE_5_6"] is 3. The totalYC should be 6 but not looping thru the entire for loop and keep on plusing.
Thanks in advance.
ycas the total of those values for that particular pass. What are you seeing that's wrong?