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

228
Visualizações
Local Storage resetting the value after page refresh

I want to input data from user input and store to local storage, but when the page get refresh the value of local storage reset. How to store all user input in local storage even I hit refresh?

JavaScript.

var myArr = [];
function botResponse(rawText) {
  var inputText = rawText;   //user input     
  myArr.push(inputText);
  var arrString = myArr.join(", ");

  var existing = localStorage.getItem('UserInput');
  existing = [];
  existing.push(arrString);
  localStorage.setItem('UserInput',existing);
 
 
  // var arrStringTwo = existing.join(", ");
  

  // Bot Response
  var new_value = window.localStorage.getItem("UserInput");  
  ----------
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're resetting it with existing = [];.

You can't store arrays directly in localStorage, it can only store strings. You need to convert to and from JSON.

  var existing = localStorage.getItem('UserInput');
  if (existing) {
    existing = JSON.parse(existing);
  } else {
    existing = [];
  existing.push(arrString);
  localStorage.setItem('UserInput',JSON.stringify(existing));
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