-3

I have this json data

myObj = {
 "job":[
  {
    "student":{
     "name" : "Agus"
   }
  },
  {
    "lecturer":{
     "name" : "Budi"
   }
  }
 ]
}

how to forEach the object and print out the property of "name" value

georg
  • 211,518
  • 52
  • 313
  • 390

1 Answers1

3

Here is a working example:

const myObj = {
  "job": [
    {
      "student": {
        "name": "Agus"
      }
    },
    {
      "lecturer": {
        "name": "Budi"
      }
    }
  ]
}

myObj.job.forEach((element) => {
  const keys = Object.keys(element);
  keys.forEach((key) => {
    console.log(element[key].name);
  })
});
Yana Trifonova
  • 586
  • 7
  • 28