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

180
Vistas
I want to take input from the user as object and push it to array that i already created in local storage

I'm having an issue with creating the array in the first place I couldn't push (person) to the array. I changed my code several times because of this error and I tried to define the array inside and outside the function but nothing changed. the error testreg.php:53 Uncaught TypeError: Cannot read properties of null (reading 'push')

Thanks for the help.

        var feedback = document.getElementById("feedback");
        var userArray = JSON.parse(localStorage.getItem("key"));
        var person = {
            name: document.getElementById("nameinput").value, 
            email: document.getElementById("emailinput").value, 
            passowrd: document.getElementById("passwordinput").value };  
        
        
        function checkemail(userArray, email) {
        var i;
        var userArray = JSON.parse(localStorage.getItem("key"));
        let isFound = false;
        if(userArray != undefined) 
        for (i = 0; i < userArray.length; i++) {
        let oldemail = userArray[i].email; 
        let newemail = document.getElementById("emailinput").value;   
        if (newemail === oldemail) { isFound = true; i = userArray.length;          

        return feedback.innerHTML = "email exist please log in or register with different email";
        }}

        if(!isFound) {
        return storeName(person, userArray);
        }}
        

        function storeName(person, userArray){ 
            var person = {
            name: document.getElementById("nameinput").value, 
            email: document.getElementById("emailinput").value, 
            passowrd: document.getElementById("passwordinput").value };
             
        var userArray = JSON.parse(localStorage.getItem("key"));
        userArray.push(person);
        userArray = JSON.stringify(userArray)
        localStorage.setItem("key", userArray);
        console.log(userArray);
                                                    }



        function clearStorage(){
        localStorage.clear();
            
                                                    }
about 4 years ago · Juan Pablo Isaza
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