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

243
Visualizações
Multiple arrays inside a array in javascript

when i do console.log(myArray) I obtain this:

console.log result

I want to take a value inside only one of this arrays, but how? When i do console.log(array[0]) I obtain this result:

37.7
28.45
36.38
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You have nested arrays. So your main array has three elements each of which contains one number, and the indexes of those arrays go from 0 to 2.

You access each nested array with its index, and then access the number with the 0 index (because there's only one element in that nested array).

const arr = [[37.7], [28.45], [36.38]];

console.log(arr[0][0]);
console.log(arr[1][0]);
console.log(arr[2][0]);

Or even loop over the array and destructure the number from each nested array:

const arr = [[37.7], [28.45], [36.38]];

for (let [number] of arr) {
  console.log(number);
}

about 4 years ago · Juan Pablo Isaza Relatório

0

Please compare your code with this working example:

let myArray = [37.7, 28.45, 36.38];
console.log(myArray[0]); // outputs 37.7
about 4 years ago · Juan Pablo Isaza Relatório

0

From what I can see in the original question so far, the output of this function is actually three different console.log() executions, which leads me to believe that whatever is firing these console.logs is actually running in some sort of loop.

If that is the case, you will not be able to pull just one value out to simply. The screenshot you added only shows the output. Could you please add the code for (or screenshot of) all the related code from setting up or fetching the array, to your console.log? With all that context, I can rewrite my answer to get you the exact answer you are looking for.

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