
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to access nested json objects in JavaScript?
Accessing nested json objects is just like accessing nested arrays. Nested objects are the objects that are inside an another object.
In the following example 'vehicles' is a object which is inside a main object called 'person'. Using dot notation the nested objects' property(car) is accessed.
Example-1
<html> <body> <script> var person = { "name":"Ram", "age":27, "vehicles": { "car":"limousine", "bike":"ktm-duke", "plane":"lufthansa" } } document.write("Mr Ram has a car called" + " " + person.vehicles.car); </script> </body> </html>
Output
Mr Ram has a car called limousine
Example-2
In the following example, an object called "air-lines" is doubly nested (nested inside a nested object). The property of that doubly nested object(lufthansa) is accessed through dot notation as shown below.
<html> <body> <script> var person = { "name":"Ram", "age":27, "vehicles": { "car":"limousine", "bike":"ktm-duke", "airlines":{ "lufthansa" : "Air123", "British airways" : "Brt707" } } } document.write("Mr Ram travels by plane called" + " " + person.vehicles.airlines.lufthanza); </script> </body> </html>
Output
Mr Ram travels by plane called Air123
- Related Questions & Answers
- How to use JavaScript map() method to access nested objects?
- How to access the JSON fields, arrays and nested objects of JsonNode in Java?
- Access objects from the nested objects structure in MongoDB
- How to access nested JSON property based on another property's value in JavaScript?
- Print JSON nested object in JavaScript?
- Constructing a nested JSON object in JavaScript
- How to access Python objects within objects in Python?
- How to count a depth level of nested JavaScript objects?
- Accessing nested JavaScript objects with string key
- Group objects inside the nested array JavaScript
- How to access properties of an array of objects in JavaScript?
- How to access methods of an array of objects in JavaScript?
- ES6 Default Parameters in nested objects – JavaScript
- How to convert nested array pairs to objects in an array in JavaScript ?
- How to parse JSON Objects on Android?
Advertisements