1. Create an array
2, by
1)push , unshift
2)splice
var ARR3 = [1,2,3,4,6 ]; var Result = arr3.splice (2,0, "SDF") // second position, delete the element 0 value inserted console.log (arr3) // [. 1, 2, "SDF",. 3,. 4,. 6]
3)length
was arr = [1,2 ]; arr[arr.length] = 3 console.log(arr); // [1, 2, 3]
3, deleted
1) Delete a: pop, shift
2)splice
was arr2 = [1,2,3,4,6 ]; were result = arr2.splice (1.3 ) the console.log (Result) // [2,. 3,. 4] deleted values the console.log (arr2 is) // [. 1,. 6] a value obtained after the deleting ---------------------------------- var arr3 = [1,2,3,4,6]; var result = arr3.splice(1,3,"sdf") the console.log (Result) // [2,. 3,. 4] deleted values the console.log (ARR3) // [. 1, "SDF",. 6] delete the inserted value
3)delete
var arr = [1, 2, 3, 4]; delete arr[0]; the console.log (ARR); // [undefined, 2,. 3,. 4] Delete Delete unchanged after the length of the array, only the elements removed is set to the undefined
4) array property length
There are t = [1,23,5,6,7 ]; t.length =3; console.log(t) // [1,23,5]
5) Empty Array
a、arr.length = 0
b、arr = [ ]
Difference: var ARR = [1,23,5,6,7 ]; var of arr1 = ARR; arr.length = 0; console.log(arr) // [] console.log(arr1) // [] ----------------------------- was Arr 2 = [1,23,5,6,7 ]; was arr3 = Arr 2; arr2 = []; console.log(arr2) // [] console.log(arr3) // [1, 23, 5, 6, 7]