2018-09-30 23:01:58 +01:00
---
id: 56bbb991ad1ed5201cd392d1
title: Updating Object Properties
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/c9yEJT4'
2019-07-31 11:32:23 -07:00
forumTopicId: 18336
2021-01-13 03:31:00 +01:00
dashedName: updating-object-properties
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
After you've created a JavaScript object, you can update its properties at any time just like you would update any other variable. You can use either dot or bracket notation to update.
2020-11-27 19:02:05 +01:00
For example, let's look at `ourDog` :
2019-05-17 06:20:30 -07:00
```js
var ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
"friends": ["everything!"]
};
```
2020-11-27 19:02:05 +01:00
Since he's a particularly happy dog, let's change his name to "Happy Camper". Here's how we update his object's name property: `ourDog.name = "Happy Camper";` or `ourDog["name"] = "Happy Camper";` Now when we evaluate `ourDog.name` , instead of getting "Camper", we'll get his new name, "Happy Camper".
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
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.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
You should update `myDog` 's `"name"` property to equal "Happy Coder".
```js
assert(/happy coder/gi.test(myDog.name));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
You should not edit the `myDog` definition.
```js
assert(/"name": "Coder"/.test(code));
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --after-user-code--
```js
(function(z){return z;})(myDog);
```
## --seed-contents--
2018-09-30 23:01:58 +01:00
```js
// Setup
var myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
2020-03-02 23:18:30 -08:00
// Only change code below this line
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
var myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
myDog.name = "Happy Coder";
```