Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda