Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda