The article is mainly about how to define the array, as well as the dynamic modification of the length of the data.
JS Array Assignment
var myarray = [];
Myarray[myarray.length] = ' new element ';
Modify JS Array length
var myarray = [1,2,3];
Myarray.length//3
Myarray.length = 2; Delete the last element
Myarray.length =//Add elements to the array; The elements have the undefined value.
Defining arrays
An array object is used to store a series of values in a separate variable name.
We use the keyword new to create an array object. The following code defines an array object named MyArray:
The Var myarray=new array () has two methods of assigning values to an array (you can add as many values as you want, as you can define any number of variables you need).
1:
var mycars=new array ()
Mycars[0]= "Saab"
mycars[1]= "Volvo"
mycars[2]= "BMW"
You can also use an integer argument to control the size of an array:
var mycars=new array (3)
Mycars[0]= "Saab"
mycars[1]= "Volvo"
mycars[2]= "BMW" 2:
var mycars=new Array ("Saab", "Volvo", "BMW")
Look at a definition of a two-dimensional array
<input value= "[[' A0 ', ' A1 '],[' B0 ', ' B1 '],[' C0 ', ' C1 ']]" "Name=" ss "Size=" "/><button onclick=" tt () "> Lést ' et</button>
<script>
function tt () {
Eval ("var aaa=" +ss.value);
For (I in AAA) for (J in Aaa[i]) a.innerhtml+= "aaa[" +i+ "[" +j+ "] = =" +aaa[i][j]+ "<br/>;}
</script>
<br/><label id= "a" ></label>