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

142
Visualizações
How to work with bi-dimensional matrix in Javascript

Today I have a quick Javascript doubt. I want to create a matrix, and be able to assign and read values from it. But I'm facing an weird issue. Take a look at the following code:


    let auxTable = Array(2).fill(Array(2).fill(null));
    
    auxTable[0][0] = 1;
    auxTable[0][1] = 2;
    auxTable[1][0] = 3;
    auxTable[1][1] = 4;

The expected output, from my point of view, would be [[1,2],[3,4]]

But I'm getting [[3,4],[3,4]] as a result.

If I do only:

    let auxTable = Array(2).fill(Array(2).fill(null));

    auxTable[1][0] = 3;
    auxTable[1][1] = 4;

The result is the same, i.e., the first index seems to be ignored.

Can someone explain why this weird behavior is happening? What is the best way to work with matrices?

Thanks, friends! :)

about 4 years ago · Juan Pablo Isaza
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