我有一个结构数组
var citizens1 = [{lat:null,lng:null,socialSecurityNumber:null}];
我想使用循环来打印每个元素的值,但这对我不起作用:
代码
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 = [];
}
}
错误
TypeError: citizens1[i].lat is undefined