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();
}