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

331
Visualizações
Get randomly generated index number (Property name) of a nested JavaScript Array and put into a variable

I have a variable with 4 indexes (nt_data). What I need to do it to be able to grab the numbers highlighted in green and add them into another variable or array. enter image description here

when I try nt_data[0] it'll list all the details including one of the numbers I want to grab (number 11):

enter image description here

and when I try nt_data[0][11] it'll show me the details inside index number 11 (which isn't an index):

enter image description here

what I need to do is to grab all of those numbers (11, 12, 3, 8) and put them into a variable so I can use them dynamically to point to that index. these numbers are randomly generated and change each time.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are trying to get key from Object, The Object.keys() method returns an array of a given object's own enumerable property names, iterated in the same order that a normal loop would.

Object.keys() returns an array whose elements are strings corresponding to the enumerable properties found directly upon object. The ordering of the properties is the same as that given by looping over the properties of the object manually.

Here's the example of retrieve key from object array:

let nt_data = [
  {11: 'a'}, {12: 'b'}, {3: 'c'}, {8: 'd'}
];

for(index in nt_data){ console.log(Object.keys(nt_data[index])[0]) }

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