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

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

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