Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!