1. One-dimensional arrays
2. Sort, find
3. Multidimensional arrays
array : The basic concept of this data type (reference type / Complex Type / composite type) array for storing a set of data.
Special emphasis : The array in JS can hold various data types (numbers, strings). )
<HTML><Head><Scriptlanguage= "JavaScript">varWeights= [3, 5, 1, 3.4, 2, -];varAll_weight= 0;varAvg_weight= 0;//Array Traversal for (varI= 0; I<weights.length; I++) {All_weight+=weights[i];} Avg_weight=All_weight/weights.length;//If you want to know the data type//Window.alert (avg_weight.constructor);//avg_weight = new number (avg_weight);//Number under the tofixed () method, converts the number to a string, and the result has a specified digit number after the decimal point. //Keep 2 digits after the decimal point, roundingDocument.writeln ("Overall weight is"+All_weight+"average weight is"+avg_weight.tofixed (2));</Script></Head><Body></Body></HTML>
Results:
Details of the array:
Basic usage
var array name = [ element value, element value ]
the array elements of Javascript can be any type of data .
For example, it can be:var arr =[4, "Hello", true]
The array exists in memory in the form of:
Test code:
<HTML><Head><Scriptlanguage= "JavaScript">varMyval= the;functionABC (val) {Val= -}abc (Myval); Window.alert (Myval); //ResultsvarMyarr=[456, -, the];functionABC2 (arr) {myarr[0]= *;}//iterate through the array before calling for (varI=0; I<myarr.length; I++) {Document.writeln (myarr[i]);} Document.writeln ("<br/>"); //456ABC2 (Myarr);//after the call, iterate over the array for (varI=0; I<myarr.length; I++) {Document.writeln (myarr[i]);} // About</Script></Head><Body></Body></HTML>
Ten JS one-dimensional arrays, one-dimensional array details