Home > Article > Web Front-end > The difference between square brackets [] and curly brackets {} in js
The content of this article is about the difference between square brackets [] and curly brackets {} in js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.
During the page development process, colleagues need to implement a three-level menu, as well as the initial selection of all and subsequent saving judgments, and choose to save all selections to json in js.
During the process, it is necessary to loop the values into json. During this period, I encountered [] and {}, so record them first.
In js, [] represents an array object, {} represents an object;
For example: var arr =[] (with var arr = new Array() is the same)
Through Google breakpoints, we can see that there is a length attribute in arr; however, the value you add to arr is in the form of key and value, and the key is a character, then the arr array It will be regarded as an associative array. The default length is 0 and the array object is Array(0). The browser breakpoint can see the data, but the value obtained is the value at the time of declaration
And: var arr = {}; arr["property name"]=property value;
This method declares an object, both arr.property name and arr["property name"] can take values;
Related recommendations:
The difference between braces and curly braces in php json_encode value_PHP
Detailed explanation of the difference between constructor with brackets and without brackets
Use JS regular expressions to replace brackets, angle brackets, etc.
Analysis of the difference between 2 equal signs and 3 equal signs in js_Basic knowledge
The above is the detailed content of The difference between square brackets [] and curly brackets {} in js. For more information, please follow other related articles on the PHP Chinese website!