I am working on a Google Maps API script but having trouble working with my arrays. The screenshot below shows my console.log statements from the code below. There are two arrays, they look exactly how I want them. I then console.log to verify the length (in this case 6). I then start a loop from 0 to 5 (6 minus 1). But the verify first console.log after than (markers[i][0]) returns TypeError: x[r] is undefined. I'm baffled by why I can clearly see the array directly above where I'm trying to extract a value.
if ($('#propertymap').length){
var map=new google.maps.Map(document.getElementById('propertymap'), {
center: {lat: 37.09024, lng: -95.712891},
zoom: 5
});
var bounds=new google.maps.LatLngBounds();
var geocoder=new google.maps.Geocoder();
var id;
var location;
var street;
var city;
var state;
var zip;
var squarefootage;
var ownedacreage;
var leasedacreage;
var hotelrooms;
var website;
var markers=[];
var infocontent=[];
$.post('/_getproperties.php', {task:'getproperties'}, function(result){
var locationsSplit=result.replace('{', '').split('}');
var i;
for (i=0; i<locationsSplit.length-1; i++){
var currentFields=locationsSplit[i].split('|');
id=currentFields[0];
location=currentFields[1];
street=currentFields[2];
city=currentFields[3];
state=currentFields[4];
zip=currentFields[5];
squarefootage=currentFields[6];
ownedacreage=currentFields[7];
leasedacreage=currentFields[8];
hotelrooms=currentFields[9];
website=currentFields[10];
geocodeAddress(location, street + ', ' + city + ', ' + state + ' ' + zip, location + '<br />' + street + '<br />' + city + ', ' + state + ' ' + zip, i);
}
console.log(markers);
console.log(infocontent);
console.log(locationsSplit.length-1);
for (i=0; i<locationsSplit.length-1; i++){
console.log(i);
console.log(markers[i][0]);
}
});
function geocodeAddress(locationtitle, locationaddress, locationdescription, i){
geocoder.geocode({'address': locationaddress}, function(results, status){
if (status==='OK'){
markers[i]=[];
markers[i][0]=locationtitle;
markers[i][1]=results[0].geometry.location.lat();
markers[i][2]=results[0].geometry.location.lng();
infocontent[i]=[];
infocontent[i][0]=locationdescription;
} else {
console.log('Geocode was not successful for the following reason: ' + status);
}
});
}
}

console.log('markers')before what you think you're logging just so you're sure.