动态的更改对象的属性名:
1.普通对象
var name = "aabbccee";
var obj = {
name:"孙悟空"
}
console.log(obj) //{name: "孙悟空"}
2.动态更改
var name = "aabbcc";
var obj1 = {
[name]:"猪八戒"
}
console.log(obj1) //{aabbcc: "猪八戒"}
动态的更改对象的属性名:
1.普通对象
var name = "aabbccee";
var obj = {
name:"孙悟空"
}
console.log(obj) //{name: "孙悟空"}
2.动态更改
var name = "aabbcc";
var obj1 = {
[name]:"猪八戒"
}
console.log(obj1) //{aabbcc: "猪八戒"}
本文标题:对象动态属性名
本文链接:https://www.haomeiwen.com/subject/nexcsktx.html
网友评论