In the previous section of JavaScript-JSON tutorial you have known that how to create an object and now in this tutorial we have provided you the way array of objects are declared in JavaScript-JSON.
In our example file we have created an object "students" which contains two array objects "Maths" and "Science" containing name, marks and age of two students. Now we can access these objects value in the following way:
"students.Maths" for accessing Maths array and "students.Science" for accessing Science array object. Now to access first element of the Maths array we can write it as "students.Maths[1]" and then we can access elements of this array as "students.Maths[1].Name" for name and "students.Maths[1].Marks" for marks of the first student in Maths and so on.
Here is the full example code for JavaScript-JSONArray.htm file.
JavaScript-JSONArray.htm
<html>
|
To run this example create JavaScript-JSONArray.htm
and run it on browser for output.

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Creating Array Objects in JavaScript with JSON View All Comments
Post your Comment