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

172
Vistas
Why does this simple javascript array fail?

I am getting old or just rusty or both, but I hang my head in shame as I bring this here because there must be something really, really simple that I am missing.

I am writing this using Google Apps script in Sheets.

Why does this fail once I reach j = 2? I have tried declaring the array in every different way I can think of, nothing gets past j=2. Wth am I missing? It's something dumb I know it.

function myFailure() {
  for (var j = 0; j < 10; j++) {
    for (var k = 0; k < 31; k++) {
      var item = 'Item '+k;
      let thisItem = new Array([],[]);
      thisItem[j][k] = item;  //the problem is happening here, once j=2 but why
      console.log(j,k);
      console.log(thisItem[j][k]);
    }
  }
}

myFailure();

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Try this:

function myFailure() {
  let thisItem = [];
  for (var j = 0; j < 10; j++) {
    thisItem[j] = []
    for (var k = 0; k < 31; k++) {
      thisItem[j][k] = `Item [${j}][${k}]`
      console.log(thisItem[j][k]);
    }
  }
}

Partial Execution log

10:04:00 AM Info    Item [0][0]
10:04:00 AM Info    Item [0][1]
10:04:00 AM Info    Item [0][2]
10:04:00 AM Info    Item [0][3]
10:04:00 AM Info    Item [0][4]
10:04:00 AM Info    Item [0][5]
about 4 years ago · Santiago Gelvez Denunciar
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