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

143
Vistas
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 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