Open zilongxuan001 opened 6 years ago
更新对象属性,可以用. 和[ ]
.
[ ]
var ourDog = { "name": "Camper", "legs": 4, "tails": 1, "friends" : ["everything!"] };
将name改为Happy Camper,如下
Happy Camper
ourDog.name = "Happy Camper"; 或者
ourDog.name = "Happy Camper";
ourDog["name"] = "Happy Camper";
Update the myDog object's name property. Let's change her name from "Coder" to "Happy Coder". You can use either dot or bracket notation.
// Example var ourDog = { "name": "Camper", "legs": 4, "tails": 1, "friends": ["everything!"] }; ourDog.name = "Happy Camper"; // Setup var myDog = { "name": "Coder", "legs": 4, "tails": 1, "friends": ["Free Code Camp Campers"] }; // Only change code below this line. myDog.name= "Happy Coder";
https://www.freecodecamp.org/challenges/updating-object-properties
介绍
更新对象属性,可以用
.
和[ ]
方法
将name改为
Happy Camper
,如下ourDog.name = "Happy Camper";
或者ourDog["name"] = "Happy Camper";
练习
代码
结果显示
来源
https://www.freecodecamp.org/challenges/updating-object-properties