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

88
Views
los índices después de 0 son el objeto correcto pero se muestran como indefinidos al acceder
class Space { constructor(x, y, c = 'grey',c2 = 'darkgrey') { this.x = x; this.y = y; this.w = 10; this.h = 10; this.c = c; this.c2 = c2; } draw() { drawSpace(this.x,this.y,this.c,this.c2) } } // Creates grid for movement function createGrid() { for (let i = 0; i < 80; i+=1) { let tempArr = []; for (let j = 0; j < 40; j+=1) { tempArr.push(new Space(i,j)); } grid.push(tempArr); } grid[0][0] = pathfinder; grid[79][0] = target; } //draws grid grid.forEach(function(e) { e.forEach(function(f) { f.draw(); }); });

Lo que no se muestra es la implementación de las variables "pathfinder" y "target". También son objetos "espaciales" con colores específicos verde/rojo respectivamente.

El problema surge con la línea grid[80][0] = target; Donde recibo un error que indica que no puedo establecer propiedades de indefinido. (configuración 0). Esto hace referencia al '0' que debería ser del índice 0 de la matriz 80. Cuando console.log(grid[80][0]); Obtengo el objeto espacial base que se configuró en el bucle for original. ¿Por qué sucede esto? ¿Cómo puedo establecer el valor del índice en el 'objetivo' del objeto espacial necesario?

Editar - El

 grid[0][0] = pathfinder; grid[80][0] = target;

está en el primer bucle for.

Edición 2: también lo hace en grid[1][0] , entiendo que la grid[80][0] no existe ya que va 0-79.

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!