
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Edit Values of an Object Inside an Array in JavaScript
For this, use the “this” keyword.
Example
Following is the code −
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);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo220.js.
Output
The output is as follows −
PS C:\Users\Amit\JavaScript-code> node demo220.js The Change First Name is=Carol
Advertisements