Dùng this trong method của object bên trong mảng để sửa thuộc tính.
Mã thực hiện
class Employee {
constructor() {
this.tempObject = [
{ firstName: "David", setTheAnotherFirstName() { this.firstName = "Carol"; } }
];
}
}
var empObject = new Employee();
empObject.tempObject[0].setTheAnotherFirstName();
console.log("The Change First Name is=" + empObject.tempObject[0].firstName);
Kết quả
The Change First Name is=Carol