Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

json with multiple objects

{
    "cars": {
        "Nissan": [
            {"model":"Sentra", "doors":4},
            {"model":"Maxima", "doors":4},
            {"model":"Skyline", "doors":2}
        ],
        "Ford": [
            {"model":"Taurus", "doors":4},
            {"model":"Escort", "doors":4}
        ]
    }
}
Comment

json with multiple objects

{
    "cars": {
        "Nissan": {
            "Sentra": {"doors":4, "transmission":"automatic"},
            "Maxima": {"doors":4, "transmission":"automatic"}
        },
        "Ford": {
            "Taurus": {"doors":4, "transmission":"automatic"},
            "Escort": {"doors":4, "transmission":"automatic"}
        }
    }
}

data.cars['Nissan']['Sentra'].doors   // 4
data.cars['Nissan']['Maxima'].doors   // 4
data.cars['Nissan']['Maxima'].transmission   // automatic

for (var make in data.cars) {
    for (var model in data.cars[make]) {
        var doors = data.cars[make][model].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}
Comment

json with multiple objects

data.cars['Nissan'][0].model   // Sentra
data.cars['Nissan'][1].model   // Maxima
data.cars['Nissan'][2].doors   // 2

for (var make in data.cars) {
    for (var i = 0; i < data.cars[make].length; i++) {
        var model = data.cars[make][i].model;
        var doors = data.cars[make][i].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: Half or Left Triangle Pattern in JavaScript 
Javascript :: how presist state in nuxt.js 
Javascript :: grab params 
Javascript :: Search products from an array by keywords in javascript 
Javascript :: i wanted to detect when a user enters an alphabet key in input text javascript 
Javascript :: destructuring interfaces in the most simple way <<Java Script 
Javascript :: lucastools version info getter 
Javascript :: p5 colored line 
Javascript :: Search products by startsWith in javascript 
Javascript :: mongoose search by keywords 
Javascript :: angular schematics tree 
Javascript :: like and dislike function 
Javascript :: lowest index 
Javascript :: go back to screen with params react native 
Javascript :: remove console messages of react-i18next 
Javascript :: comparing oblects 
Javascript :: variable local and global 
Javascript :: how we can use pagination in angular material and spring boot 
Javascript :: circle rect collision 
Javascript :: express plus es6 
Javascript :: Google Maps JavaScript API warning: InvalidKey https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key 
Javascript :: loose and strict equality 
Javascript :: graphql get item by id from strapi react 
Javascript :: provider._web3Provide.sendAsync as any 
Javascript :: how to create an object that stores personal data in javascript 
Javascript :: remove all special characters online 
Javascript :: Public properties can be created via Static public fields 
Javascript :: javascript condition based on table cell value 
Javascript :: jit and aot 
Javascript :: node javascript retry promise.all 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =