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

147
Vistas
get value of second data which has the same name as first data with javascript

so I have this json

items: [
  {
    id: 123
  },
  {
    id: 456
  }
]

and I am trying to get the value with javascript of the second id which has a value of 456, but I have no idea how to because it doesnt have a specified parent by which I could get it.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your use case isn't exactly clear so the best answer I have for this is to specify the index:

const data = [
  {
    id: 123
  },
  {
    id: 456
  }
];

const secondId = data[1]?.id;

If you are looking for a specific id you can use the find method:

const data = [
  {
    id: 123
  },
  {
    id: 456
  }
];

const secondObj = data.find(a => a.id === 456);

It should also be noted that if you're hitting an API that's querying a database you can't expect that 456 will always be the second object unless the backend code is explicitly ordering it this way.

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