如何编辑类中数组内对象的值 - JavaScript?
javascriptweb developmentfront end technologyobject oriented programming更新于 2026/1/6 3:56:17
为此,请使用“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
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

