I want to create 4 new users,
let JonSnow = new User({ id: 1, name: 'Jon Snow', status: Status.user });
let AryaStark = new User({ id: 2, name: 'Arya Star', status: Status.user });
let SansaStark = new User({ id: 3, name: 'Sansa Stark', status: Status.user });
let JoffreyBaretheon = new User({ id: 4, name: 'Joffrey Baretheon', status: Status.user });
In my User class I have a allUser
function,
allUsers() {
let users: IUser[] = [];
let user: IUser = {
id: this.id,
name: this.name,
status: this.status
}
users.push(user);
users.forEach((user) => console.log(user));
return users;
}
If I call the the function like so,
JonSnow.allUsers();
AryaStark.allUsers();
SansaStark.allUsers();
JoffreyBaretheon.allUsers();
It calls the allUsers
function 4 times, as expected.
How would I store all 4 new users into one array? So I would only need to call the function once to show all users?