[英]How to add another variable into an existing object?
I have an object that I am passing through multiple pages and I want to add another variable into it and am not sure how to do that.我有一个对象,我正在通过多个页面,我想向其中添加另一个变量,但不知道该怎么做。
I have tried tried just equating the object to the variable I want to add but that just overwrites the object.我曾尝试将对象等同于我想添加的变量,但这只会覆盖对象。
The Object物体
this.appDetails = {
Maids: Details.Maids,
length: Details.length,
cMats: Details.cMats,
specialReq: Details.specialReq,
Address: Details.Address,
Date: Details.Date,
Payment: "By Credit/Debit Card",
UID: this.id
}
The variable I want to add我想添加的变量
var M = document.getElementById('Mobile').textContent;
this.appDetails = {
Maids: Details.Maids,
length: Details.length,
cMats: Details.cMats,
specialReq: Details.specialReq,
Address: Details.Address,
Date: Details.Date,
Payment: "By Credit/Debit Card",
UID: this.id
}
addNewProperty(){
this.appDetails.M = document.getElementById('Mobile').textContent;
//or
this.appDetails["M"] = document.getElementById('Mobile').textContent;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.