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 :: current date minus days javascript 
Javascript :: get index of selected option javascript 
Javascript :: delete all node_modules folders recursively windows 
Javascript :: how to pass sequelize transaction to association helper method 
Javascript :: nuxt looks for npm_modules on express 
Javascript :: fetch javascript 
Javascript :: NameError: uninitialized constant Shoulda 
Javascript :: add date in javascript 
Javascript :: get first day of the week of a given date javascript js 
Javascript :: jquery window redirect with header 
Javascript :: jquery get radio checked value 
Javascript :: json array to string in postgresql 
Javascript :: regex to match string not in between quotes 
Javascript :: regex not contain 
Javascript :: get status of a user discord js 
Javascript :: await useeffect javascript 
Javascript :: killall node windows 
Javascript :: validate phone number javascript 
Javascript :: .find() is not a function 
Javascript :: how to fix header on scroll 
Javascript :: for loop on a array 
Javascript :: json.stringify formatting 
Javascript :: onloadscroll to top 
Javascript :: convert nodes to array javascript 
Javascript :: hot reload problem react 17 
Javascript :: how to change style of an element using javascript 
Javascript :: js multiple url fetch 
Javascript :: show hide more text jquery 
Javascript :: select2 clear fields 
Javascript :: jquery contains text 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =