Home Internet JSON Tutorial – Create An Array Is JSON

JSON Tutorial – Create An Array Is JSON


JSON Array

An array is like a variable which can hold multiple content and value with same type . Learn more about it read this what is an array .

JSON arrays format and syntax most like defining JSON variable .

Format & Syntax

var objectName = [ "value" , "value", "value" , "value" , "value"   ] ;

In this code var is sytax to define array . objectName is used to create object . value is the value of the object  .

To understand this with an example


In a car showroom have 5 cars with different colors . Cars colors are Red, Green, Blue , Silver , Purple . In this case Car Color is object and colors are values of the object . To write this format is

var carColor = ["red","green","blue","purple","silver"] ;
document.write( carColor[0] );

Now this is an array .

In first line of code object carColor values are defined (red , green ……silver ) .

And in the next line when you want to get specific value of the array, you will write index number[0 ,1 ,2 …..] on the value . index number 0 is used for first value and index number 1 is used for second value as so on .

READ ALSO : -  What Is Variable In Computer Programming

Test It’s Working

Nested Array

var carColor = ["red","green","blue","purple","silver"] ;
var busColor = ["Golden","black","brown"] ;
var vahicleColors = {arry1:carColor ,array2:busColor} ;
document.write( vahicleColors.arry1[3] );

In nested array, you can create nested array which store more than one array values . In the upper code you understand line 1 and line 2 format in the top section.

In the third line of code

var vahicleColors = {arry1:carColor ,array2:busColor} ;

format is same as declare the variable ,but difference is that array1 and arry2 hold multiple (5 + 3) values itself . In means in the third line array vahicleColors hold total 8 values .

Five values of first carColor and three values of busColor . In fourth line” document.write()” you get the value “purple ” when you run script . Which is the fourth value of carColor array .

To display array value format is


Test Nested Array Working