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

219
Visualizações
How is this code rewriting the variable through the loop?

I understand how the loop works here but I'm slightly confused as to how I am able to keep re-writing the data variable and it still returns the entire <tr> body?

I would have expected the last statement </tr> to be the final value of data but somehow it's including everything and returning a complete HTML block.

Noob question, but I can't figure it out. I've never worked with HTML like this.

let data = "";

if (this.tasks.length > 0) {
  for (let i = 0; i < this.tasks.length; i++) {
    data += '<tr>'
    data += '<td>'+(i+1)+". " + this.tasks[i] + '</td>';
    data += '<td><button onclick="app.Edit(' + i + ')"  class="btn btn-warning">Edit</button></td>';
    data += '<td><button onclick="app.Delete(' + i + ')"  class="btn btn-danger">Delete</button></td>';
    data += '</tr>';
  }
}
about 4 years ago · Juan Pablo Isaza
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