Array
Arrays: Regardless of the type, can be stored. Storage is in a certain order.
Order: The index number starts at 0.
1, need to initialize the array first
var array//Array name = new Arrary ()//array Note case
Method of assigning values
array[0]= value 1
array[1]= Value 2
array[2]= Value 3
Array[3]= Value 4
Other usage
Sort, ascending
Array.Sort ();
Flip, want to arrange in descending order, you need to first sort ascending, then flip the whole array
Array.reverse ();
Finds the index number of the first occurrence of the value, and returns 1 if it cannot be found
Alert (Array.indexof (6));
Finds the index number of the last occurrence of this value, and returns 1 if it cannot be found
Alert (Array.lastindexof (2));
pops up the value on the last index, which is equivalent to removing the last
Alert (Array.pop ());
To push a value into an array, increase the length by 1, and increase the index number by 1
Array.push (4.4);
Iterate through the collection, replacing the index number with the newly defined variable name
If you want to print each element of an array, place the variable in the brackets after the name of the arrays as an index to use
for (var aa in array)
{document.write (array[aa]+ "<br/>")}
Bubble Contrast method
A[0]=5
A[1]=4
A[2]=7
A[3]=3
A[4]=1
Compare results
5 4 7) 3 1
4 5 7) 3 1
4 5 7) 3 1
3 5 7) 4 1
1 5 7) 4 3
1 5 7) 4 3
1 4 7) 5 3
1 3 7) 5 4
1 3 4) 5 7
1 3 4) 5 7
JavaScript array and Bubble Sort method