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

138
Vistas
How can I append user inputs in a single array on localStorage key in reactjs?

Every time a new input is entered, I am trying to make it so that input is appended into an array in localstorage. I am currently using localStorage.setItem('Inputs', JSON.stringify(document.getElementById("inputVal").value)) which takes the value but does not add it to any array and instead replaces the previous value. How would I go abouts adding the input into an array for localstorage? I am also wondering if I could use .appendChild()?

quick update: I have also tried

var valueS = document.getElementById("inputVal").value;
    const arr = [];
    const newArry = [
      ...arr,
      valueS
    ]
    //arr.push(valueS)
    localStorage.setItem('Data', JSON.stringify(newArry))
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just like @nIta, @Patrick Evans and @David Grosh pointed out, the const arr = [] should contain the localstorage array.

The solution that works for me is as follows:

var valueS = document.getElementById("inputVal").value;
    const arr = [JSON.parse(localStorage.getItem('Data'))];
    const newArry = [
      ...arr,
      valueS
    ]
    localStorage.setItem('Data', JSON.stringify(newArry))
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