I have the following data and tried the following, but I am unable to get the names
of sub_values
(like: Test1, Test5, Test10, Test20, Test50
) either in [object Object]
format or in json
format and unable to show its length
either (i.e 5, means we have sub_values names
are five, so its length is 5).
var jsondata = [
{"id": "1","name": "test1","sub_values": [{"id": "1","name": "Test1","sub_values": []}]},
{"id": "2","name": "test2","sub_values": [{"id": "1","name": "Test5","sub_values": []},{"id": "1","name": "Test10","sub_values": []},{ "id": "1","name": "Test20","sub_values": []}]},
{"id": "3","name": "test3","sub_values": [{"id": "1","name": "Test50","sub_values": []}]}
];
console.log(jsondata);//(3) [Object, Object, Object]
console.log(jsondata.sub_values.name);//Cannot read property 'name' of undefined
console.log(jsondata.sub_values.length);//Cannot read property 'length' of undefined
Error: Cannot read property 'name' of undefined
Cannot read property 'length' of undefined
Please let me know how to get this.
Created Fiddle.