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

208
Views
Read data from Json and store in variable javascript

I am getting a response of an api request in JSON format which I store in a variable with json data like this structure

const users=    {
    'ABC': {
        id: '123',
        name:'testname',
    },
    'DEF': {
        id = '222',
        name='testname2'
    }
}

I am trying to read each data under users and store in a different variable. One variable lets say name firstVar which will have all date under 'ABC' and secondVar which will have all data under'DEF' which i can then use for further tests. I am not sure how to achieve it. Any help will be appreciable.

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

0

If you want to get the ids of each object and store them you can map over the Object.values and return an array of ids.

const users = {
  'ABC': {
      id: '123'
  },
  'DEF': {
      id: '222'
  }
};

const ids = Object.values(users).map(el => {
  return el.id;
});

console.log(ids);

about 4 years ago · Juan Pablo Isaza Report

0

Not sure if this is what you want, your code is cut off. Array.prototype.find function only works for Array.

const users = {
    'ABC': {
        id: '123'
    },
    'DEF': {
        id: '222'
    }
};

const foundId = Object.keys(users).find(username => users[username].id === '123');

users[foundId] // found user.
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!