---
title: "How to remove a property from a JavaScript?"  
description: "How to remove a property from a JavaScript?"  
author: "Ravi Vishwakarma"  
published: 2021-07-19  
updated: 2023-06-07  
canonical: https://answers.mindstick.com/qa/93780/how-to-remove-a-property-from-a-javascript  
category: "web application"  
tags: ["javascript", "html5", "css cascading style sheets"]  
reading_time: 3 minutes  

---

# How to remove a property from a JavaScript?

How to [remove](https://yourviews.mindstick.com/view/81420/this-is-no-time-to-remove-obamacare-for-usa-under-covid-19-pandemic) a [property](https://www.mindstick.com/articles/44059/couple-of-supportive-tips-when-taking-a-gander-at-property-for-sale) from a [JavaScript](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript)?

## Answers

### Answer by user

The delete operator deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions. The **delete** operator deletes a property from an object.

```
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Properties</h2>
<p>You can delete object properties with the delete keyword.</p>
<p id='demo'></p>
<script>
var person = {
  firstname: 'John',
  lastname: 'Doe',
  age: 50,
  eyecolor: 'blue'
};
delete person.age;
document.getElementById('demo').innerHTML =
person.firstname + ' is ' + person.age + ' years old.';
</script>
</body>
</html>
```

\

### Answer by Ethan Karla

delete operator removes a property from an object in javascript, its single operand property must be an access expression, deletes the value of not only the property but also the value.

1. The delete keyword removes a property from an object.
2. The delete keyword deletes both the property's value and the property itself.
3. After deletion, the property cannot be used before adding it back again.
4. It has no effect on the variable or function.

Syntax

```
delete object-name.property-name
```

Example

```
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Object Properties</h2>
<h1 id='hh'></h1>
<h2 style='color :red'>after deleting the age property from an object</h2>
<p id='demo'></p>
<script>
var person = {
  firstname: 'John',
  lastname: 'Doe',
  age: 50,
  eyecolor: 'blue'
};
document.getElementById('hh').innerHTML =person.firstname + ' is ' + person.age + ' years old.';
delete person.age;
document.getElementById('demo').innerHTML =
person.firstname + ' is ' + person.age + ' years old.';
</script>
</body>
</html>
```

Output

JavaScript Object Properties

## John is 50 years old.

## after deleting the age property from an object

John is undefined years old.

### Answer by Muskan Digital

In JavaScript, you can remove a property from an object using the **delete** operator. Here's how you can do it:

```plaintext
var obj = { property1: "value1", property2: "value2", }; // Remove a property delete obj.property1; // Check if the property is removed console.log(obj.property1); // Output: undefined
```

In the above example, we have an object `obj` with two properties `property1` and `property2.` To remove `property1`, we use the `delete` operator followed by the object name and the property name `(delete obj.property1)`.

After removing the property, if you try to access it, it will return `undefined`, as demonstrated by `console.log(obj.property1)`.

Note that the `delete` the operator removes the property from the object directly. If the property is inherited from a prototype chain, it will not affect the original prototype object.

To know with better understanding, you can join the Java training in Indore, Delhi, Meerut, Noida, Lucknow, Jaipur, Bhopal, Mumbai and other cities in India, choose your nearby location which is acceptable to you.


---

Original Source: https://answers.mindstick.com/qa/93780/how-to-remove-a-property-from-a-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
