2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: 56bbb991ad1ed5201cd392d3
|
|
|
|
title: Delete Properties from a JavaScript Object
|
|
|
|
challengeType: 1
|
2019-02-14 12:24:02 -05:00
|
|
|
videoUrl: 'https://scrimba.com/c/cDqKdTv'
|
2019-07-31 11:32:23 -07:00
|
|
|
forumTopicId: 17560
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
|
|
|
<section id='description'>
|
|
|
|
We can also delete properties from objects like this:
|
|
|
|
<code>delete ourDog.bark;</code>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id='instructions'>
|
|
|
|
Delete the <code>"tails"</code> property from <code>myDog</code>. You may use either dot or bracket notation.
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
2018-10-04 14:37:37 +01:00
|
|
|
tests:
|
2019-11-27 02:57:38 -08:00
|
|
|
- text: You should delete the property <code>"tails"</code> from <code>myDog</code>.
|
2019-07-13 00:07:53 -07:00
|
|
|
testString: assert(typeof myDog === "object" && myDog.tails === undefined);
|
2019-11-27 02:57:38 -08:00
|
|
|
- text: You should not modify the <code>myDog</code> setup.
|
2019-07-13 00:07:53 -07:00
|
|
|
testString: 'assert(code.match(/"tails": 1/g).length > 1);'
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
// Example
|
|
|
|
var ourDog = {
|
|
|
|
"name": "Camper",
|
|
|
|
"legs": 4,
|
|
|
|
"tails": 1,
|
|
|
|
"friends": ["everything!"],
|
|
|
|
"bark": "bow-wow"
|
|
|
|
};
|
|
|
|
|
|
|
|
delete ourDog.bark;
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
var myDog = {
|
|
|
|
"name": "Happy Coder",
|
|
|
|
"legs": 4,
|
|
|
|
"tails": 1,
|
|
|
|
"friends": ["freeCodeCamp Campers"],
|
|
|
|
"bark": "woof"
|
|
|
|
};
|
|
|
|
|
2020-03-02 23:18:30 -08:00
|
|
|
// Only change code below this line
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
### After Test
|
|
|
|
<div id='js-teardown'>
|
|
|
|
|
|
|
|
```js
|
2018-10-20 21:02:47 +03:00
|
|
|
(function(z){return z;})(myDog);
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
var ourDog = {
|
|
|
|
"name": "Camper",
|
|
|
|
"legs": 4,
|
|
|
|
"tails": 1,
|
|
|
|
"friends": ["everything!"],
|
|
|
|
"bark": "bow-wow"
|
|
|
|
};
|
|
|
|
var myDog = {
|
|
|
|
"name": "Happy Coder",
|
|
|
|
"legs": 4,
|
|
|
|
"tails": 1,
|
|
|
|
"friends": ["freeCodeCamp Campers"],
|
|
|
|
"bark": "woof"
|
|
|
|
};
|
|
|
|
delete myDog.tails;
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|