0

I have a student record. I want this JSON to be looped and I am getting undefined with using SchoolRecord.classX[1]

 var SchoolData = {
     "SchoolRecord": {
         "classX": {
             "name": "Student Name 1",
             "subject": {
                 "mathsDept": {
                     "subject": "Maths",
                     "marks": 87
                 },
                 "scienceDept": {
                     "subject": "Physics",
                     "marks": 55
                 },
                 "socialDept": {
                     "subject": "Social",
                     "marks": 95
                 }
             }
         },
         "classIX": {
             "name": "Student Name 2",
             "subject": {
                 "mathsDept": {
                     "subject": "Maths",
                     "marks": 99
                 },
                 "scienceDept": {
                     "subject": "Physics",
                     "marks": 95
                 },
                 "socialDept": {
                     "subject": "Social",
                     "marks": 91
                 }
             }
         }
     }
 }

 console.log(SchoolData.SchoolRecord);
 console.log(SchoolData.SchoolRecord[0]);

http://jsfiddle.net/mvxkpttg/1/

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

0 Answers0