zilongxuan001 / LearnFreecode

0 stars 0 forks source link

Updating Object Properties #252

Open zilongxuan001 opened 6 years ago

zilongxuan001 commented 6 years ago

介绍

更新对象属性,可以用.[ ]

方法

var ourDog =  {
  "name": "Camper",
  "legs": 4,
  "tails": 1,
  "friends" : ["everything!"]
};

将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";

结果显示

image

来源

https://www.freecodecamp.org/challenges/updating-object-properties