There are two basic ways that JavaScript creates arrays. The first is the use of the array constructor.
var colors = new Array ();
var colors = new Array (20);
var colors = new Array ("Red", "Blue", "green");
Another way is to omit the new symbol:
var colors = Array (3);
var colors = Array ("Greg");
1. Detecting arrays
if (value instanceof Array) {}
if (Array.isarray (value)) {}
2. Conversion method
Tolocalstring () converts the array to a local array and returns the result.
ToString () converts the array to a string and returns the result.
ValueOf () returns the original value of the array object.
Join () Places all elements of an array into a string. element is delimited by the specified delimiter.
3. Stack method
Push () adds one or more elements to the end of the array and returns the new length.
Pop () deletes and returns the last element of the array.
4. Queue method
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.
5. Reorder Methods
Reverse () Reverses the order of the elements in the array.
Sort () Sorts the elements of an array.
6. How to Operate
Concat () joins multiple arrays.
Slice () Creates a new array based on one or more items in the current array.
Splice () Inserts an item into the middle of the array.
7. Location method
IndexOf () looks backwards from the beginning of the array.
LastIndexOf () looks forward from the end of the array.
8. Iterative Methods
Every () runs the given function for each item in the array, and returns True if every item of the function returns True.
The filter () runs the given function for each item in the array, returning the new array of items that the function returns as true.
ForEach () runs the given function for each item in the array. This method has no return value.
Map () runs the given function for each item in the array, returning a new array that consists of the results of each function call.
Some () runs the given function for each item in the array, and returns True if the function returns true for either item.
9. Merge method
ECMAScript5 New Method:
Reduce () iterates over each item in an algebraic group, and then builds the final return value. Start with the first item.
Reduceright () iterates over each item in an algebraic group, and then builds the final return value. Start with the last item.
~ ~ ~ Night Plus Example ~ ~
JavaScript Array Method Summary