इसके लिए, "this" कीवर्ड का उपयोग करें।
उदाहरण
निम्नलिखित कोड देखें:
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);
उपरोक्त प्रोग्राम चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा:
node fileName.js.
यहां, मेरा फ़ाइल नाम demo220.js है।
आउटपुट
आउटपुट इस प्रकार है:
PS C:\Users\Amit\JavaScript-code> node demo220.js The Change First Name is=Carol