Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
How to get key from json in angular

How to get key "employee "

{ employee":{"name":"John","age":12}

}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It's not about Angular, this is plain Javascript:

const obj = { employee:{name:"John",age:12}}

const key = Object.keys(obj)[0]
about 4 years ago · Juan Pablo Isaza Report

0

You can use forEach to get your output if you use Array Object

function example1(array){

    let res = [];
  array = [{"ex1":{"name":"John1","age":12}}, {"ex2":{"name":"John2","age":12}}, {"ex3":{"name":"John3","age":12}}]

    array.forEach((e, idx) => {
    res.push(Object.keys(e))
  })

  document.getElementById("ex1").innerHTML = JSON.stringify(res);
}
<input type="button" value="example1" onclick="example1()">  

<p id="ex1"></p>

if you just use only object you can use For...in to get your output

function example2(array){

    let res = [];
  obj = {"ex1":{"name":"John1","age":12}, "ex2":{"name":"John2","age":12}, "ex3":{"name":"John3","age":12}}

    for(var val in obj){
    res.push(val)
  }

  document.getElementById("ex2").innerHTML = JSON.stringify(res);
}
<input type="button" value="example2" onclick="example2()">  

<p id="ex2"></p>

But remember when you put object or array or whatever check its valid or not. In your object is invalid here is the correct format

{"employee":{"name":"John","age":12}}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!