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

142
Views
¿Cómo crear una matriz llena de cualquier cantidad de matrices vacías en JavaScript?

Según el título, estoy tratando de crear una matriz que se llene con cualquier cantidad de matrices vacías en JavaScript.

Como ejemplo, digamos que quería crear una matriz con 9 matrices vacías. Podría hacer algo como esto, que funciona, pero se ve bastante mal:

 let myArray = [[], [], [], [], [], [], [], [], []];

Intenté usar el método de relleno, pero si presiono cualquiera de las matrices vacías, las otras matrices también se llenan:

 let myArray = Array(9).fill([]); myArray[0].push(1); // Output = [[1], [1], [1], [1], [1], [1], [1], [1], [1]];

¿Hay una mejor manera de hacer esto? ¿Quizás una buena frase?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Rellénelo con Array.fill , luego map sobre cada elemento:

 let myArray = Array(9).fill().map(e => []) myArray[0].push(1); console.log(myArray)

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