This article provides a simple js introduction tutorial, which is a js array definition and array length instance tutorial. If you are learning js arrays, we will tell you how to define arrays and increase arrays and array length calculation examples.
Let's take a look at how to define an array
var a = new array();var b = new array(8);var c = new array("first", "second", "third");Or array direct quantity:
The code copy is as follows: var d = ["first", "second", "third"];
Let's take a look at it, add an element behind the array
var myarray = [];myarray[myarray.length] = 'new element';
The length of the array
array has only one attribute, length . length represents the number of memory space occupied by the array, not just the number of elements in the array. In the array defined just now, the value of b.length is 8.
<script>var a = new Array("first", "second", "third")a[48] = "12"document.write(a.length)//The result displayed is 49</script>Let's take a look at the example of modifying the array length
var myarray = [1,2,3];myarray.length // The initial length is 3myarray.length = 2; // Delete the last element myarray.length = 20 // Add 18 elements to the array
To view more JavaScript syntax, you can follow: "JavaScript Reference Tutorial" and "JavaScript Code Style Guide". I also hope that everyone will support Wulin.com more.