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

227
Vistas
I couldn't push the object person to an array that is stored in local storage, the erorr is (Cannot read properties of null (reading 'push'))
<p class="center" >
        name:<br> <input type="text" id="nameinput" required><br>
        email:<br><input type="email" id="emailinput" required><br>
        password:<br><input type="password" id="passwordinput" required><br>
        <button id="registerbutton" onclick="co`enter code here`ntainsObject()">Register<button>
    <p><br><p id="feedback"></p><br>
    <button onclick="clearStorage()">Clear Storage</button>
   
     <body id="body">
        <script>
            var userArray = [];
            var person = {};
            var newemail;
            var oldemail;
            var feedback = document.getElementById("feedback");
            person.name = document.getElementById("nameinput").value;
            person.email = document.getElementById("emailinput").value;
            person.password = document.getElementById("passwordinput").value;
            JSON.parse(localStorage.getItem(userArray));
            
            function containsObject(newemail, userArray) {
                newemail = document.getElementById("emailinput").value;
            
                oldemail = localStorage.email;
            
                if (newemail === oldemail) {
                    feedback.innerHTML = "email exist";
                } else {
                    storeName();
                }
            }
            
            
            function storeName(person, userArray) {
            
            
                let newarray = JSON.parse(localStorage.getItem(userArray));
                newarray.push(person);
                userArray = newarray;
                localStorage.setItem("person", JSON.stringify(userArray));
                console.log(userArray);
            }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Hi Mohammed when using the local storage you always must first initialize a value before altering it. Here an example : Initializing :

  localStorage.setItem('user1', 'Mohammed');
Then you can query the local storage to retrieve the value :

localStorage.getItem('user1')

Or you can overwrite its value :

localStorage.setItem('user1','Jip')

Important to know is that both the key and its assigned value must be strings. So when you want to store and initialize an array of users the array must be stored as a string. To repeat the process for your use case : Initializing :

localStorage.setItem('users',"[]")

Reading :

localStorage.getItem('users')

Altering its value :

let users = JSON.parse(localStorage.getItem('users'))
users.push('Jip')
users = JSON.stringify(users)
localStorage.setItem('users',users)

I hope this is what you needed.

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