Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete an attribute with a javascript object

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today Xiaobian to share with you how to use javascript object to delete an attribute of the relevant knowledge points, detailed content, clear logic, I believe that most people are too aware of this knowledge, so share this article for your reference, I hope you will learn something after reading this article, let's take a look at it.

In javascript, you can use the delete operator to delete the properties of an object in the syntax format "delete object. Property name;". When an object property is deleted, instead of setting the property value to undefined, the property is completely purged from the object.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

In javascript, objects are referential, composite data; object properties are also known as name-value pairs, including attribute names and attribute values. 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.

Delete attribut

Use the delete operator to delete the properties of an object.

Example 1

The following example uses the delete operator to delete the specified property.

Var obj = {x: 1, y: 2, z: 3}; / / define the object delete obj.x; / / delete the properties of the object xconsole.log (obj.x); / / return undefinedconsole.log (obj)

Output:

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.

These are all the contents of the article "how to delete an attribute with a javascript object". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report