I have a array like this:
var ret = ["-37.8497", "144.968", "Albert Park Grand Prix Circuit", "2.76083", "101.738", "Sepang International Circuit","26.0325", "50.5106", "Bahrain International Circuit",...]
and i want it to be like this:
var markers = [
{latLng: [45.616944, 9.2825], name: 'Italian Grand Prix'},
{latLng: [52.0732605, -1.0166426], name: 'British Grand Prix'},
{latLng: [43.7345, 7.4214], name: 'Monaco Grand Prix'},
{latLng: [49.332, 8.58], name: 'German Grand Prix'}, ...]
I implemented this function:
var j=0;
for (i = 0; i < ret.length; i+=3)
{
markers[j].latLng[0] = ret[i];
markers[j].latLng[1] = ret[i+1];
markers[j].name = ret[i+2];
j++;
}
And i get this error:
Uncaught TypeError: Cannot read property '0' of undefined
in the first line of the for.
I googled for a while but it seemed to be that javascript has not a true support for multiples arrays. Can you help me with the correct implementation?