Please see my code below.
class User {
constructor(name, email) {
this.name = name;
this.email = email;
}
addUser() {
users.push(this.name, this.email)
}
}
const userOne = new User ('John', '[email protected]');
const userTwo = new User ("Alan", "[email protected]");
let users = [];
userOne.addUser();
userTwo.addUser();
After method addUser i have array with names and emails but i would like to have an array with objects as below
users = [
{ name: 'John', email: '[email protected]' }
{ name: 'Alan', email: '[email protected]' }
]
How my method addUser should looks in my prototype and if variable users is in correct place or can be store somewhere in Class? Thanks in advance
users = [userOne, userTwo];?