Forum Moderators: open
var celBody = [
{'id':'Sun', 'data':[696342, 696342, 0, 0, 0]},
{'id':'Mercury', 'data':[2439.7, 2439.7, 0.449505, 0.35758, 223.74798]},
{'id':'Venus', 'data':[6051.8, 6051.8, 0.7188755, 3.34309, 155.5424]},
{'id':'Earth', 'data':[6378.137, 6356.7523, 0.9850864, 0, 128.14849]},
{'id':'Mars', 'data':[3396.2, 3376.2, 1.4345873, -0.61867, 28.94692]}];
var celBody = {
'Sun': [696342, 696342, 0, 0, 0],
'Mercury': [2439.7, 2439.7, 0.449505, 0.35758, 223.74798],
'Venus': [6051.8, 6051.8, 0.7188755, 3.34309, 155.5424],
'Earth': [6378.137, 6356.7523, 0.9850864, 0, 128.14849],
'Mars': [3396.2, 3376.2, 1.4345873, -0.61867, 28.94692]
};
for(i = 0; i < Object.keys(celBody).length; i++){}
Object.keys(celBody)[i]
celBody[Object.keys(celBody)[i]][3]
To easily loop through the bodies, is this the best way:
var i, n;
for (i = 0, n = Object.keys(celBody).length; i < n; i++) { }
for (var property in celBody) {
if (celBody.hasOwnProperty(property)) {
// do something with property and/or celBody[property]
}
}
Is the easiest way to get a key name by index:
Is this the best way to get a data field by index of the body:
var celBodyKeys = Object.keys(celBody);
// looping stuff
celBody[celBodyKeys[i]][3]