JavaScript Basics 07 - Variable Expansion - Array

Hello, everyone, I am Lei Gong!
I check in and learn a little bit every day. Today I will continue to learn the basics of JavaScript. The following are study notes.

1. Basic introduction to arrays

Array - An elegant way to store a set of data under a single variable name.

Insert image description here

Arrays have the same role as variables and are also used to store data in programs.
The difference between an array and a variable:
a variable can only store one value at a time, and an array can store multiple values ​​at a time.

2. Basic applications of arrays

1. Declaration syntax

let 数组名 = [数据1,数据2,……,数据x]

Example:

let names = ['雷工',‘吴工’,‘高工’,'龚工',‘费工’]

1.1. The array is saved in order, so each data has its own number;
1.2. The numbering in the computer starts from 0, so the numbering in the array also starts from 0, 0,1,2,...;
1.3. In an array, the number of data is also called an index or subscript;
1.4. An array can store any type of data.

2. Get value syntax

array name[subscript]

Example:

let names = ['安工',‘石工’,‘孟工’,'白工',‘冯工’]
names[0]   //  安工
names[2]   //  孟工

2.1. Get the data through subscripts.
2.2. Access the data according to the characteristics of this type.

3. Some terms
3.1. Element: Each data stored in the array is called an array element;
3.2. Subscript (index): the number of the data in the array;
3.3. Length: the number of data in the array, through the length of the array Property acquisition.

Example:

let names = ['盖工',‘韩工’,‘宋工’,'田工',‘王工’]
console.log(names[2])   //  宋工
console.log(names[3])   //  田工
console.log(names.length)   //  5

3. Postscript

The above is the basic knowledge about arrays.
If you insist on studying for 30 minutes every day, you will find that the time you spend watching videos every day will be 30 minutes less, and you will be less happy by 30 minutes.

Guess you like

Origin blog.csdn.net/u013097500/article/details/132733220