English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
【JS Object Property Query and Setting】
You can use either the dot (.) or bracket ([:]) operator to get the value of the property. The left side of the operator should be an expression that returns an object. For the dot (.), the right side must be a simple identifier named after the property name. For the bracket ([]), the expression inside the brackets must be a string that is calculated to be the property name:
<script type="text/javascript"> var author = book.author; //Get the 'author' property of book var name = author.subname; //Get the 'surname' property of author var title = book["main title"]; //Get the 'main title' property of book </script>
When accessing object properties using the dot (.) operator, the property name is represented by an identifier. Identifiers must appear directly in the JavaScript program, and they are not data types, so the program cannot modify them.
Conversely, when accessing object properties using [], the property name is represented as a string. Strings are a data type in JavaScript, which can be modified and created during program execution.
<script type="text/javascript"> var addr = ""; for(i=0;i<4;i++{ addr += cutomer["address" + i] + "\n"; } </script>
This code reads the address0,adddress of the customer object1,address2,adddress3Properties, and connect them together.
This is the full content of the brief introduction of the differences between dot (.) and bracket ([:]) in js object properties brought to you by the editor. I hope everyone will support and cheer for the tutorial!