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

154
Views
How to fix "push is not a function"?

I am trying to create a delete button to remove item rows from a table, but I am constantly encountering an "Uncaught TypeError: deletedArr.push is not a function". I am not sure what to do. Here is the code:

//Remove buttom
$(document).ready(function() {
   // As soon as jquery loads, load from storage
   // it will return null if nothing is stored yet
   const deletedExpenses = JSON.parse(localStorage.getItem('deletedExpenses')) || [];

   $('body').on('click', '.deleteButton', function(e) {
     e.preventDefault(); // prevent the href default 
     // if you need to access the id...
     let deleteID = $(this).data('id');
     $(this).closest('tr').remove();

     // You first have to load from storage the array of deleted items,
     var deletedArr = localStorage.getItem("deletedExpenses");

     // If you have nothing stored, this will return null,
     // And if that's the case, create new array
     if (!deletedArr){
       deletedArr = [];
     }
     
     // then push to this array another ID that got deleted
     deletedArr.push(deleteID);
     localStorage.setItem('deletedExpenses', JSON.stringify(deletedArr));
   })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This sets the variable to a string:

var deletedArr = localStorage.getItem("deletedExpenses");

When you set the local storage value you encode it to JSON, so you need to parse it back from JSON when reading it:

var deletedArr = JSON.parse(localStorage.getItem("deletedExpenses"));
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!