I have a function which creates an object of values, but im getting this in my console log:
x: Array[4]
0: undefined
1: NaN
2: undefined
3: NaN
length: 4
y: Array[4]
0: undefined
1: NaN
2: undefined
3: NaN
length: 4
The function loops on an object created from a PHP file which was json encoded:
var sdata = {"4":{"7":["1","7","2","2"]},"3":{"3":["2","8","1","1"]}};
My function is:
function populate_collisions(){
gcollision = {
x: [],
y: []
};
for(var key in sdata){
gcollision.x.push( sdata[key][0] );
gcollision.x.push( sdata[key][0] + (sdata[key][2]-1) );
gcollision.y.push( sdata[key][1] );
gcollision.y.push( sdata[key][1] + (sdata[key][3]-1) );
}
console.log(gcollision);
}
I'm curious to know why im getting undefined and NaN? And how do i solve the problem?