You are defining list as object
. Object properties are in order of they defined, but we cannot trust its order . I think there is Chrome bug about it https://code.google.com/p/v8/issues/detail?id=164
the following first
method gives first element from list object , this function will works most cases , if object is empty it will return undefined
value.
var data = {
"_id":"123",
"list":{
"56":{"name":"Great ","amount":100,"place":"Town"},
"57":{"name":"Great 2","amount":200,"place":"City"}
},
"pop":[2,3]
};
function first( data ){
for ( var i in data ){
if ( data.hasOwnProperty(i) ) break;
}
return data.hasOwnProperty(i) ? data[i] : undefined;
}
first( data.list ).amount;
If you want to keep order of list .. define them as Array
. example
var data = {
"_id":"123",
"list":[
{"id" : "56" ,"name":"Great ","amount":100,"place":"Town"},
{"id" : "57" ,"name":"Great 2","amount":200,"place":"City"}
],
"pop":[2,3]
};
and access them as data.list[0]