Home > Web Front-end > JS Tutorial > body text

How to delete object attributes in javascript

醉折花枝作酒筹
Release: 2023-01-04 09:35:23
Original
30571 people have browsed it

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".

How to delete object attributes in javascript

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

How to delete object attributes in javascript##

var a = {aa: 1,bb:2}
Reflect.deleteProperty(a, 'aa')
Copy after login

method 2: Using the delete keyword

delete obj.age
console.log(obj) // { name: 'xiaoming', id: 2 }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template