Method call of the Array object in JavaScript
Method concatfor loop and for in Loop
<Script type = text/javascript> alert (2); var arr = [,]; alert (arr); alert (length: + arr. length); var arr2 = [6, 8, 9, 5, 4]; alert (arr2); alert (arr2 [0]); alert (arr. concat (arr, arr2); for (var x in arr2) {alert (x ++ arr2 [x]);} alert (23); </script>
Join pop shift
Var arr = [,]; var arr2 = [, 4]; alert (arr. join (-); alert (arr. pop (); // Delete and return the last element. If the array is empty, // This method does not change the array and returns the undefined value alert (arr. shift (); // Delete and return the first element of the array
Join pop shift push unshift reverse
Var arr = [,]; var arr2 = [, 4]; var arr3 = [0]; alert (arr. join (-); alert (arr. pop (); // Delete and return the last element. If the array is empty, // This method does not change the array and returns the undefined value alert (arr. shift (); // Delete and return the first alert element of the array (push: + arr3.push )); // 5 add one or more elements to the end of the array, and return the new array length alert (unshift + arr3.unshift (3, 2 )); // 7 add one or more elements to the beginning of the array, and return the new length of the array alert (arr3); alert (arr3.reverse (); // reverse the order of elements in the array.
Sort
var arr2=[6,8,50,9,5,4];alert(arr2.sort(sortNumber));function sortNumber(a,b){ return a-b}