I was trying to create an instance of a constructor function if one of the array elements created from the instance of the constructor does not have the same email.
let users = [];
class User{
constructor(email, name, age, lang){
this.email = email;
this.name = name;
this.age = age;
this.lang = lang
}
save(){
users.push(this)
}
}
function validate(email, name, age, lang){
let uEmail = email;
users.forEach(ele =>{
if(ele.email == email){
console.log('You have account with us')
}else if(!ele.email){
creatObj(uEmail, name, age, lang)
}
})
}
function creatObj(email,name, age, lang){
new User('[email protected]',name, age, lang).save()
}
when I ran the code with the same email I need the not to push that instance to the users array.
unfortunately it keeps pushing the instance even if the condition is not met.

Can anyone help?