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

207
Visualizações
How to make my Array to be empty again and reusable for my Edit Text Function

Newbie here.. I was making an expense note app(just a noob app). I have this button function on which when I select one table row.. It will be deleted and the table row input text value will return to the input bar text area(name, date, amount, remarks). I was happy when it work.

But it only work once.

Because when I select different table row data. It will be deleted but the same "first input data value" will always return to the input text bar..

It seems the first table data are being saved in the empty array function that can be reuse again. What I am hoping for is when I use the empty array function it will be empty again to be use in another different table row data.

I am using array methods but failed or my If statement is wrong. Hopefully you can answer this :) thanks

document
  .getElementById("editSelection")
  .addEventListener("click", editSelection);

function editSelection() {
  var editName = [];
  var editDate = [];
  var editAmount = [];
  var editRemarks = [];

  let selectedRows = document.getElementsByClassName("selected-row ");
  while (selectedRows.length > 0) {
    editName.push(cell0.innerText);
    editDate.push(cell1.innerText);
    editAmount.push(cell2.innerText);
    editRemarks.push(cell3.innerText);

    selectedRows[0].parentNode.removeChild(selectedRows[0]);

    var name = document.getElementById("inputName");
    name.value = editName.join("\n");

    var date = document.getElementById("inputDate");
    date.value = editDate.join("\n");

    var amount = document.getElementById("inputAmount");
    amount.value = editAmount.join("\n");

    var remarks = document.getElementById("inputRemarks");
    remarks.value = editRemarks.join("\n");
  }

  if (name || date || amount || remarks) {
    editName.splice([0], editName.length);
    editDate.splice([0], editDate.length);
    editAmount.splice([0], editAmount.length);
    editRemarks.splice([0], editRemarks.length);
  }
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you define an empty array

var editName = [];

and fill it with values you can empty it again with

editName = [];
about 4 years ago · Juan Pablo Isaza 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