I want to define a two dimensional array object with for loop... my problem I think my object didn't really get processed, here's the code :
var newLoc = [];
var index;
for (index = 0, i < locations.length; i++){
if(i == 0) {
newLoc[i][0] = locations[i][1];
newLoc[i][1] = locations[i][2];
}
else {
if(locations[i][8] == locations[i-1][8]){
newLoc[i-1][0] = (locations[i][1] + locations[i-1][1])/2;
newLoc[i-1][1] = (locations[i][2] + locations[i-2][1])/2;
}
else{
newLoc[i][0] = locations[i][1];
newLoc[i][1] = locations[i][2];
}
}
}
locations array itself is the old array which store the data for new array (newLoc). locations' data are existing which are coordinate latitude and longitude. I suppose there is something wrong with my for loop form or how I declare newLoc 2 dimension array, but I still don't know how to fix it. Any help appreciated.
for (index = 0, i < locations.length; i++){should befor (var i = 0; i < locations.length; i++){right? ( note the;)var i; for(i = 0; i < locations.length; i++) {...}. and i can't understand how it should works.