Home > Article > Web Front-end > How to delete object attributes in javascript
JS method to delete object properties: 1. Use the deleteProperty method, the syntax "Reflect.deleteProperty (array name, "name of the element object")"; 2. Use the delete keyword, the syntax "delete array name. Attributes".
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.
Method 1: Use the deleteProperty static method of the Reflect object in ES6
##
var a = {aa: 1,bb:2} Reflect.deleteProperty(a, 'aa')
method 2: Using the delete keyword
delete obj.age console.log(obj) // { name: 'xiaoming', id: 2 }delete can only delete the attributes on the object, but not the defined variables, and this Operator/behavior is very slow[Recommended learning:
javascript video tutorial】
The above is the detailed content of How to delete object attributes in javascript. For more information, please follow other related articles on the PHP Chinese website!