Home > Web Front-end > JS Tutorial > The difference between square brackets [] and curly brackets {} in js

The difference between square brackets [] and curly brackets {} in js

不言
Release: 2018-08-15 17:17:54
Original
4416 people have browsed it

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

Simple summary of single quotes and braces in PHP strings The difference between double quotes, php string

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template