diff --git a/curriculum/challenges/english/blocks/lecture-introduction-to-javascript-objects-and-their-properties/6732b721eb98f224868b44a6.md b/curriculum/challenges/english/blocks/lecture-introduction-to-javascript-objects-and-their-properties/6732b721eb98f224868b44a6.md index 04bb13715c4..1eb4ad78a56 100644 --- a/curriculum/challenges/english/blocks/lecture-introduction-to-javascript-objects-and-their-properties/6732b721eb98f224868b44a6.md +++ b/curriculum/challenges/english/blocks/lecture-introduction-to-javascript-objects-and-their-properties/6732b721eb98f224868b44a6.md @@ -5,12 +5,14 @@ challengeType: 19 dashedName: how-can-you-remove-properties-from-an-object --- -# --description-- +# --interactive-- There are several ways to remove properties from an object, with the `delete` operator being the most straightforward and commonly used method. When you use `delete`, it removes the selected property from the object. Here's an example of how to use the `delete` operator: +:::interactive_editor + ```js const person = { name: "Alice", @@ -23,10 +25,14 @@ delete person.job; console.log(person.job); // undefined ``` +::: + In this example, we start with a `person` object that has three properties: `name`, `age`, and `job`. Then, we use the `delete` operator to remove the `job` property. After the deletion, the `person` object no longer has the `job` property. Another way to remove properties is by using destructuring assignment with rest parameters. This approach doesn't actually delete the property, but it creates a new object without the specified properties: +:::interactive_editor + ```js const person = { name: "Bob", @@ -41,6 +47,8 @@ const { job, city, ...remainingProperties } = person; console.log(remainingProperties); ``` +::: + In this example, we use destructuring to extract `job` and `city` from the `person` object, and collect the remaining properties into a new object called `remainingProperties`. This creates a new object without the `job` and `city` properties. Understanding how to remove properties from objects is an important skill in JavaScript programming. It allows you to manipulate objects dynamically, and clean up unnecessary data.