Array classification:
1. The subscript of the array is divided into index array and associative array
/* Index array, which is usually called an array */
var ary1 = [1,3,5,8];
//Get array elements by index, starting from 0 (of course some languages start from 1)
//The index is actually an ordinal number, an integer number
alert(ary1[0]);
alert(ary1[1]);
alert(ary1[2]);
alert(ary1[3]);
/* Associative array refers to an array accessed with a non-ordinal type as a subscript. It is called a dictionary in Python */
var ary2 = {};
//When accessing, use non-ordinal numbers (numbers), here is a string
ary2["one"] = 1;
ary2["two"] = 2;
ary2["thr"] = 3;
ary2["fou"] = 4;
2. Data storage is divided into static arrays and dynamic arrays
// Static array in java
// After definition, the length of the array is fixed and cannot be changed. Access the array elements by index
Int[] ary1 = {1,3,6,9};
//Dynamic array in java
// The implementation of ArrayList in java is based on Array. Here, dynamic arrays are generalized, no matter what method is used to implement them.
List ary2 = new ArrayList();
ary2.add(1);//Elements can be added dynamically, and the length of the array also changes
ary2.add(3);
ary2.add(6);
/* js arrays are dynamic arrays */
var ary = [];//Define an array with unspecified length
ary[0] = 1; //Elements can be added dynamically
ary.push(3);
ary.push(5);
alert(ary.join(","));//Output 1,3,5
The array of js belongs to both index array and dynamic array, because it is essentially a js object, which embodies the dynamic language characteristics of js. However, the index array of js does not "continuously allocate" memory, so the indexing method does not bring high efficiency. Arrays in Java allocate memory continuously.