Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda