How to remove a property from an object in ES?

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

Introduction

In ES6, we may wish to remove a property from an object.

In this article, we'll learn how to remove a property from an object in ES6.

How to remove a property from an object in ES

To remove a property from an object we can use an ECMAScript 6 destructuring feature:

const obj = {
    "attr1": "value1",
    "attr2": "value2",
    "attr3": "value3"
};

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

A JavaScript expression that enables the unpacking of array values or object attributes into separate variables is the destructuring assignment syntax.

Conclusion

To remove a specific property from an object in ES6 we can use the destructing feature.

{{ message }}

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