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

The object property operation looks like this

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, Xiaobian will bring you about the operation of object attributes. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.

var mi = { name: 'Xiaoming', birth: 1990, school: 'No.1 Middle School', //if special characters are quoted in quotes eg: 'school-name':'xxx'mi ['school-name'] height: 1.70, weight: 65, core: null}; The first property acquisition method: mi ['name ']; // ' Xiaoming 'The second property acquisition method: mi.name; // 'Xiaoming'

Access mi's name attribute, mi.name is written more concisely. When we write JavaScript code, we try to use standard variable names for attribute names, so that we can directly access an attribute in the form of object. prop.

You can also add and delete attributes

Add: mi.age; //undefined mi.age = 18; //Add an age attribute mi.age //Output 18 Delete: delete mi.age;mi.age //undefined

If we want to check whether xiaoming has an attribute, we can use the in operator:

'name' in mi; // true'grade' in mi; // false

Be careful, though, if in judges that an attribute exists, this attribute may not necessarily be mi's, it may be inherited by mi:

'toString' in mi; // true

Because toString is defined in the object object, and all objects eventually point to object on the prototype chain, mi also has the toString attribute.

To determine whether a property is owned by mi itself rather than inherited, use the hasOwnProperty() method:

mi.hasOwnProperty ('name '); // truemi.hasOwnProperty ('toString'); // false The above is the object attribute operation shared by everyone. If there is a similar doubt, please refer to the above analysis for understanding. If you want to know more about it, 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

Development

Wechat

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

12
Report