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

198
Views
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 answers
Answer question

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 Report
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!