This article provides a simple JS introductory tutorial, this is a JS array definition and array length example tutorial, if you are learning the JS array, we show you here how to define the array and increase the array and array length calculation instances.
Let's take a look at how to define an array
Copy Code code as follows:
var a = new Array ();
var b = new Array (8);
var c = new Array ("A", "second", "third");
or the direct amount of the array:
Copy Code code as follows:
var d = ["A", "second", "third"];
Next, add an element after the array
Copy Code code as follows:
var myarray = [];
Myarray[myarray.length] = ' new element ';
The length of the array
Array has only one property, that is, Length,length represents the number of memory space occupied by an array, not just the number of elements in the array, the B.length value is 8 in the array just defined
Copy Code code as follows:
<script>
var a = new Array ("A", "second", "third")
A[48] = "12"
document.write (A.length)
The result shown is 49
</script>
Let's take a look at modifying an array length instance
Copy Code code as follows:
var myarray = [1,2,3];
Myarray.length//Initial length is 3
Myarray.length = 2; Delete last Element
Myarray.length = 20//Add 18 elements to array
See more JavaScript syntax, you can focus on: JavaScript reference tutorial, JavaScript Code style guide, and also hope that many people support the cloud-Habitat community.