2.4 KiB
2.4 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
587d7b7c367417b2b2512b1b | Use the delete Keyword to Remove Object Properties | 1 | 301168 |
Description
foods
object example one last time. If we wanted to remove the apples
key, we can remove it by using the delete
keyword like this:
delete foods.apples;
Instructions
oranges
, plums
, and strawberries
keys from the foods
object.
Tests
tests:
- text: 'The <code>foods</code> object should only have three keys: <code>apples</code>, <code>grapes</code>, and <code>bananas</code>.'
testString: 'assert(!foods.hasOwnProperty(''oranges'') && !foods.hasOwnProperty(''plums'') && !foods.hasOwnProperty(''strawberries'') && Object.keys(foods).length === 3);'
- text: The <code>oranges</code>, <code>plums</code>, and <code>strawberries</code> keys should be removed using <code>delete</code>.
testString: assert(code.search(/oranges:/) !== -1 && code.search(/plums:/) !== -1 && code.search(/strawberries:/) !== -1);
Challenge Seed
let foods = {
apples: 25,
oranges: 32,
plums: 28,
bananas: 13,
grapes: 35,
strawberries: 27
};
// Only change code below this line
// Only change code above this line
console.log(foods);
Solution
let foods = {
apples: 25,
oranges: 32,
plums: 28,
bananas: 13,
grapes: 35,
strawberries: 27
};
delete foods.oranges;
delete foods.plums;
delete foods.strawberries;
console.log(foods);