I have an array with the structure
var citizens1 = [{lat:null,lng:null,socialSecurityNumber:null}];
I would like to use a loop to print the values of each element however this does not work for me:
Code
function animate(index,d) {
if (d>eol[index]) {
marker[index].setPosition(endLocation[index].latlng);
if(marker[index].getPosition() == endLocation[index].latlng){
console.log('Completed'+' '+index);
}
return;
}
var p = polyline[index].GetPointAtDistance(d);
marker[index].setPosition(p);
updatePoly(index,d);
timerHandle[index] = setTimeout("animate("+index+","+(d+step)+")", tick);
citizens1.push({lat:marker[index].getPosition().lat(),lng:marker[index].getPosition().lng(),socialSecurityNumber:global_citizens[index].socialSecurityNumber});
if(citizens1.length = '500'){
console.log('500 records saved');
window.clearTimeout( timerHandle);
for(var i = 0; i < citizens1.length ; i++){
console.log(citizens1.lat +',' +citizens1.lng+','+citizens1.socialSecurityNumber);
}
citizens1 = [];
}
}
Error
TypeError: citizens1[i].lat is undefined
namea typo just in here, or in your real program as well?console.log(Students[i])instead and see what's really there.