I am learning how to make constructors in Javascript, so far so good but I am struggling how to make an method that will delete specific items from the array.
I want whenever I call Manager.fireEmployee(nameOfEmployee) to delete that employee from the array.
Also is there a way whenever I create new employee from the constructor that will be pushed automatically inside the array?
Here is the code:
class Employee {
constructor(name, department) {
this.name = name;
this.department = department;
}
whoAreYou() {
return `My name is ${this.name} and I am working in ${this.department} department`;
}
};
class Manager extends Employee {
constructor(name) {
super(name, 'General');
}
fireEmployee(nameOfEmployee){
// how to make this method so when I type the name of the employee it will remove it from the array?
}
};
class SalesPerson extends Employee {
constructor(name, quota) {
super(name, 'Sales', quota);
this.quota = quota;
}
};
let michael = new Manager('Michael');
let pam = new Employee('Pam', 'Marketing');
let jim = new SalesPerson('Jim', '1000');
let dwight = new SalesPerson('Dwight', '1200');
let arr = [pam, jim, dwight];