Home >Web Front-end >Front-end Q&A >How to delete object attributes in es6
es6 Method to delete object attributes: use delete operator, syntax "delete object name.property name". Using the delete operator to delete an object property does not set the property value to undefined, but completely clears the specified property from the object.
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
Attributes are also called name-value pairs, including attribute names and attribute values. The attribute name can be any string including the empty string. There cannot be two attributes with the same name in an object. Attribute values can be any type of data.
In js, if you want to delete object attributes, you can use the delete operator.
The delete operator can delete the properties of an object.
Example: Use the delete operator to delete the specified attribute.
var obj = {x : 1}; //定义对象 delete obj.x; //删除对象的属性x console.log(obj.x); //返回undefined
When an object property is deleted, instead of setting the property value to undefined, the property is completely cleared from the object. If you use a for/in statement to enumerate object properties, only properties with a property value of undefined will be enumerated, but deleted properties will not be enumerated.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to delete object attributes in es6. For more information, please follow other related articles on the PHP Chinese website!