Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use es6 to delete object properties

Shulou Source: shulou.com Published: 2022-06-03 16:00:01 10月04日 Update

This article shows you how to use es6 to delete object properties, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

Es6 method to delete object properties: use the delete operator, syntax "delete object name. property name". Using the delete operator to delete an object property, instead of setting the property value to undefined, completely clears the specified property from the object.

The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.

An attribute is also called a name-value pair, including the attribute name and the attribute value. The property name can be any string that contains an empty string, and there cannot be two properties with the same name in an object. Property values can be any type of data.

In js, to delete object properties, you can use the delete operator.

The delete operator removes the properties of an object.

Example: use the delete operator to delete the specified property.

Var obj = {x: 1}; / / define the object delete obj.x; / / delete the property xconsole.log (obj.x) of the object; / / return undefined

When an object property is deleted, instead of setting the property value to undefined, the property is completely purged from the object. If you use the for/in statement to enumerate object properties, you can only enumerate properties whose value is undefined, but not deleted attributes.

The above is how to delete object properties using es6. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Properties objects operators content skills knowledge concise concise two characters strings that is tutorials data articles methods more environment computers examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux NVidia MariaDB MySQL