Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!