-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

2
  • 1
    Please be aware that it's not JSON data. What have you tried so far? Please add a minimal reproducible example Commented Jun 18, 2021 at 9:22
  • 2
    PLEASE, DON'T SHOUT (and write a more descriptive title while you're at it) Commented Jun 18, 2021 at 9:22

1 Answer 1

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);
  })
});

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.