Advertise with us

Nested Arrays

Nested Arrays in JSON Objects ?

Last updated:7/3/2018 4:25:04 AM

1 Answers

Prakash nidhi Verma
Prakash nidhi Verma

Arrays as JSON Objects :

JSON array are almost the same as arrays in JS. Values must be string, number, object, array, boolean or null type in JSON array. 

Example : 

[ "Allahabad", "Kanpur", "Varansi" ]

Array values by using a for-in loop: 

for (i in myObj.city) { 
    x += myObj.city[i];
}

Nested Arrays in JSON Objects: 

myObj = { 
    "name":"Prakash",
    "age":19,
    "city": [
        { "name":"Allahabad", "models":[ "Sangam"] },
        { "name":"Kanpur", "models":[ "Industrial"] },
        { "name":"Varansi", "models":[ "Devnagari" ] }
    ]
 }
delete myObj.city[1];    //Delete array 

Answer