In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the characteristics of javascript object". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the characteristics of javascript object"?
The characteristics of javascript object: 1, the "key-value pair" list of the last attribute to a comma end; 2, the use of const declaration of the object, its data can be modified; 3, the attribute name can be "[value]" way; 4, the "in" operator must be the left side of the attribute name, the right is the object name, returned is a Boolean value.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Nine characteristics of js object
First: the last attribute in the key-value pair list ends with a comma
This comma has a high-end name: trailing comma (trailing)
The reason should be for standardization, simply for beauty.
Second: the data of objects declared with const can be modified.
The properties inside the object can be modified.
It is not possible to change the object as a whole.
Third: multi-word attributive names to make trouble.
If the key in the key-value pair, that is, the name in name: "zhangsan" becomes "new name".
Changing a name from one word to more than one word can change some things.
The point doesn't work anymore. It used to be person.name, but now you can't write person.new name.
Should write person ["new name"]
When you encounter multi-word names, remember three points:
Use parentheses
First name in quotation marks
You can write a string directly in parentheses or a variable, because a string can also be written in a variable.
Fourth: there is also an odd way for attribute names, square brackets []
Let name= "apple" var o = {[name]: 5,} alert (o.apple)
Remember, what is stored in square brackets is not a definite, rigid fixed value, but a variable, okay?
The flexible one.
Fifth: in special cases, attribute values can be abbreviated.
Function makeUser (name, age) {return {name: name, age: age, / /. Other attributes};} let user = makeUser ("John", 30); alert (user.name); / / John
As you can see, the attribute name is the same as the variable name.
At this point, you can write it differently:
Before the change: name:name
After change: name
What's the point? It is a convenience, in a sense, it also increases the burden of beginners, so everything has two sides, nothing but nothing.
Sixth: the attribute name can be picked up at will.
You don't have to worry that keywords can't be used anymore (why do you have to use keywords? It hurts to be idle)
Remember one thing: the property of _ _ proto__. We can't set it to a non-object value.
Seventh: the role of "in"
"key" in object
The property name is in the object.
The in must have an attribute name on the left, an object name on the right, and a Boolean value of true or false returned.
The property name is usually a string, but it can also be a variable, and the string is still stored in the variable.
So the string is still working.
Why in?
For fear that undefined will make trouble.
Eighth: for...in cycle
Syntax format:
For (key in object) {/ / A code executed for each key in this object property}
Among them, except for the uncertainty of key on the left side of in (which can be replaced by other words), the structure of the other words is determined.
The side reflects that the important thing in this statement is "which object is to be traversed?"
Ninth: the order of object attributes
A concept: integer attribute names
The attribute name is an integer string
Another concept: integer string
A string that can be converted to an integer
"1", "2" and so on are integer strings.
Remember:
When the attribute name is not an integer string, traversing the output data of the object is in the order in which it was created
When the attribute name is an integer string, in the order from smallest to largest.
Thank you for your reading, the above is the content of "what are the characteristics of javascript object". After the study of this article, I believe you have a deeper understanding of the characteristics of javascript object, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.