How to make a check on "registered users"?

https://codepen.io/ruf1x/pen/YzXXwpq
The essence of the code is that when the page runs through promty requested name/surname and if everything meets the condition, it creates a User object instance, and ushitsa in the userList array and the result is displayed in the console.
But I have a problem: I can't do a condition to check already registered users.
April 7th 20 at 10:59
2 answers
April 7th 20 at 11:01
Solution
something like this?
this.users.find(user => user.first === first && user.last === last)
// user || undefined
I probably melts, but I can't catch up, what do I do
As I understand it, I need to make a condition something like:
if (this.users.find(user => user.first === first && user.last === last)) {
alert('User registered');
continue;
} ??? - saul_Dickins commented on April 7th 20 at 11:04
@saul_Dickins, Yes, it is a condition to check already registered users :)
if the user is already in an array, then users.find will return that user, if not, returns undefined - Teresa29 commented on April 7th 20 at 11:07
April 7th 20 at 11:03
function UserList() {
 this.users = [];


 this.has = function(User) {
 return this.users.find(u => 
 u.firstName = = = 'User'.firstName
 && u.lastName === User.lastName
 ) !== undefined
}

 this.add = function(User) {
 if (this.has(User)) {
 throw 'Error. Such a user is already registered'
}
this.users.push(User);
}

// ...
}


//...


 else {
 fullName = fullName.split(' ');
 user.firstName = fullName[0];
 user.lastName = fullName[1];
 try {
 userList.add(user); 
 } catch(e) {
alert(e)
}
 }

Find more questions by tags JavaScript