如何在类中的数组对象中编辑值 - JavaScript?
为此,使用“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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP