7.1 Arrays
①javascript arrays are used in many ways, and elements in an array do not have to be exactly the same type
Two ways to construct a ② array:
A. Constructors for arrays
var arrayname=new array ()///empty array var arrayname=new array (4)/////Length 4 array var arrayname=new array ("Thomas", "Roger",-3, " Plastic "); Array of 4 elements
B. Array literals notation
var arrayname=[];//empty array var arrayname=["Thomas", true,-3];//three elements of an array var arrayname=[3];//an array of elements
7.2 Properties of an array (because the array is an object in JavaScript, it has properties and methods)
This is just a description of the length property, which is described in the other sections later.
var stu=["Thomas", "Roger", "Amber", "Jen"];stu.length=2;//shorten the array, now the array has only the first two elements stu.length=7;//an array of growth, adding 5 elements at the end, Their values are undefined. Stu[9]= "Mary";//increment array, length 10, index 9 that is, tenth element value is Mary, others are undefined
7.3 Methods of arrays
①sort method
②concat () method
③slice (Start,stop) method: Gets an array of sub-arrays, custom start and end indexes, sub-arrays include start index, no end index.
④splice (Start delete index, delete element number, [added element]) method
var arr=["Orange", "apple", "pear", "Grape"];var arr1=arr.splice (2,1, "watermelon", "plum"), arr1=["Orange", "Apple", " Watermelon "," plum "," grape "];
Seventh Chapter-javascript Arrays