Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

fetch inner json object using javascript / node js

I am new to node and I am trying to fetch name from the obj but the problem is

How to fetch data from inner json object as my json object look like this

let obj= 
{
  "h4354desdfqw":{
   name:"Computer",
   os:"Window",
  },
  "hjsado24334":{
   name:"Software",
   type:"Adobe",
  },
  "qwsak032142":{
   name:"hardware",
   type:"hardisk",
  },
}

console.log(obj.h4354desdfqw.name)

I am trying to fetch all the name which are present inside the json object
like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

computer
Software
hardware

>Solution :

I am not sure in which representation you would like get the data. I can assume – you would like to get array of the names

let obj= 
{
  "h4354desdfqw":{
   name:"Computer",
   os:"Window",
  },
  "hjsado24334":{
   name:"Software",
   type:"Adobe",
  },
  "qwsak032142":{
   name:"hardware",
   type:"hardisk",
  },
}

const result = Object.values(obj).map(i => i.name);

console.log(result)

Object.values(obj).map(i => console.log(i.name));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading