1. Initialization of the array:
Three initialization modes new array (); new array (size); new Array (element0, element1, ..., ELEMENTN);
2. Properties
Constructor returns a reference to the array function that created this object. Length Sets or returns the number of elements in the array. Prototype gives you the ability to add properties and methods to objects.
3. Methods
Concat () joins two or more arrays and returns the result.
Use:
Arrayobj.concat (Aobj1,aobj2 ...);
Join () Places all elements of an array into a string. element is delimited by the specified delimiter.
ToString () converts the array to a string and returns the result.
ValueOf () returns the original value of the array object
Use:
Arr.join (".") Arr.tostring ()//default with comma ', ' split
Pop () deletes and returns the last element of the array
Push () adds one or more elements to the end of the array and returns the new length.
Use:
Arrobj.pop (); Arrobj.push ("theme");
Shift () deletes and returns the first element of the array
Unshift () adds one or more elements to the beginning of the array and returns the new length.
Use:
Arrobj.shift () arrobj.unshift ("Element1")
Reverse () Reverses the order of the elements in the array.
Use:
Arrobj.reverse ()
Tosource () returns the source code of the object.
Arrobj.tosource (); ["George", "John", "Thomas"]
Sort () Sorts the elements of an array
Use:
var ArrA = [6,2,4,3,5,1]; function desc (x, y) { if (× > return-1); if (x < y) return 1; } function asc (x, y) { if (× > y) return 1; if (x < y) return-1; } Alert (Arra.sort (ASC)) //Ascending alert (Arra.sort (DESC))//descending order
Slice () returns the selected element from an existing array
Use:
Arra.slice (2,4) //Returns an element with an index of 2 to 4 [2,4] before closing //4,3
Splice () Deletes the element and adds a new element to the array. Returns the deleted item
Use:
Arrayobject.splice (index,howmany,item1,....., ItemX)
Index required. An integer that specifies the location of the Add/remove item, using a negative number to specify the position from the end of the array.
Howmany required. The number of items to delete. If set to 0, the item is not deleted.
Item1, ..., ItemX Optional. Adds a new item to the array.
JS Object-Oriented Learning note three (Array object)