I am adding different objects to an array based on certain conditions.I think i am repeating the same code multiple times.Any suggestion to write the codes in better way.
this.users.forEach((item) => {
const student = this.students.find((id) => item.user.id == id);
if(student) {
this.schools.push({
'type':'Student',
'info':[{
'name': item.name,
'id': item.Id,
}],
});
}
const teacher = this.teachers.find((id) => item.user.id == id);
if(teacher) {
this.schools.push({
'type':'Teacher',
'info':[{
'name': item.name,
'id': item.Id,
}],
});
}
const staff = this.staffs.find((id) => item.user.id == id);
if(staff) {
this.schools.push({
'type':'Staff',
'info':[{
'name': item.name,
'id': item.Id,
}],
});
}
});
},