
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to use JavaScript map() method to access nested objects?
Let’s say the following is our nested objects −
var details = [ { id:"101", firstName:"John", lastName:"Smith", age:25, countryName:"US", subjectDetails: { subjectId:"Java-101", subjectName:"Introduction to Java" }, }, { "uniqueId": "details_10001" } ]
Use map() along with typeOf to access nested objects. Following is the code −
Example
var details = [ { id:"101", firstName:"John", lastName:"Smith", age:25, countryName:"US", subjectDetails: { subjectId:"Java-101", subjectName:"Introduction to Java" }, }, { "uniqueId": "details_10001" } ] details.map((nestedObject)=>{ if (typeof nestedObject.subjectDetails != 'undefined') console.log("The subject Name="+nestedObject.subjectDetails.subjectName); })
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo119.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo119.js The subject Name=Introduction to Java
- Related Articles
- How to access nested json objects in JavaScript?
- Access objects from the nested objects structure in MongoDB
- JavaScript: How to map array values without using "map" method?
- How to count a depth level of nested JavaScript objects?
- How to use nested while loop in JavaScript?
- How to use nested for loop in JavaScript?
- How to access the JSON fields, arrays and nested objects of JsonNode in Java?\n
- How to use JavaScript to create client-side image map?
- How to convert nested array pairs to objects in an array in JavaScript ?
- How to access properties of an array of objects in JavaScript?
- How to access methods of an array of objects in JavaScript?
- How to access Python objects within objects in Python?
- How to access elements of nested lists in R?
- How to access nested JSON property based on another property's value in JavaScript?
- Accessing nested JavaScript objects with string key

Advertisements