Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the basic knowledge of JS array

Shulou Source: shulou.com Published: 2022-06-02 06:49:34 10月22日 Update

What is the basic knowledge of JS array, many novices are not very clear about it. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Array: storing an ordered set of data

The role of arrays: storing multiple data at a time

How the array is defined:

1. Constructor definition array: var array name = new Array ()

2. Literal definition array: var array name = []

The meaning of the following array:

Var array name = new Array (); / empty array var array name = new Array (value); / / array definition, length var array name = new Array (value 1, value 2, value 3.); / define array and have multiple data var array names = []; / empty array var array name = [value 1, value 2, value 3]; / / there are three data

Array elements: the data stored in the array

Array length: the number of elements in the array

Array index (subscript): starts at 0 and ends with the length of the array minus 1

Set the element value of the array through the subscript: array name [index] = value

Access the element value of the array through the subscript: array name [index]

The meaning of the following array:

Var arr1=new Array (); / / empty array var arr2=new Array (5); / / an array of length 5, and the value of each data is undefinedvar arr3=new Array (1mai 2mine3); / / an array of 5 fractions in length, var arr4= []; / an empty array var arr5= [1recover2d3]; / / an array of length 3 var arr6= ["red", "blue", "green", 1parentin true]; / / the types of values of elements in the array can be different var arr7= [] / / set the value of the elements of the array arr7 [0] = 10 * arr7 [1] = 20; is it helpful for you to read the above? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Array element data length subscript index storage knowledge meaning multiple that is way help basics order clarity one-time three number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Apple macOS Huawei