Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda