How to access nested object in ReactJS

The format of an object in Javascript ot ReactJs can be nested many times and can get complicated quickly.How to access nested object in ReactJS.

var student = {
      "name":"Dheeraj",
      "age":44,
      "books": {
         "chemistry":"The Chemical chain",
         "physics":"Elberts Thoery",
         "Maths":"Integration & Derivatives"
      }
      "address":"Jaipur"
     }

Now an above object student can be used in your project but how to consume it.

We can use this method

student[2]['books'].chemistry 

Or 

student[2].books.chemistry 

So using [] we can access any index of an object . [] is used for indexing . The indexing starts from 0,1,2,3…..So to access three you will use [3]

See our More Project in Laravel and ReactJS

Theme Color change in React JS

Records display in Material UI Table

Display Records in Model Box in React

Responsive Navbar in Material UI React

Upload PDF file in React, Laravel

Leave a Reply

Your email address will not be published. Required fields are marked *