How to remove a property from a JavaScript object?

September 28, 2022 No comments js property remove javascript tips solutions

Introduction

In JavaScript, there are situations when we wish to remove a property from a JavaScript object.

In this post, we'll present how to remove a property from an object in JS.

How to remove a property from a JavaScript object

To remove a property from an object we use the JavaScript delete operator:

var obj = {
    "attr1": "value1",
    "attr2": "value2",
    "attr3": "value3"
};
delete obj.attr1;

console.log(obj); // { attr2: "value2",  attr3: "value3" }

Conclusion

To remove a property from an object in JavaScript we can use the delete operator.

In ES6, we can use destructuring feature to remove a property from an object.

{{ message }}

{{ 'Comments are closed.' | trans }}