Arrays can be created in following ways:
Constructor:
var colors = new Array(); // array
var colors = new Array("blue","green","brown"); // array with 3 colors
var colors = new Array(5); // array with 5 items
Array Literal:
var colors = [];
var colors = ["blue","green","brown"];
| PROPERTY | DESCRIPTION |
|---|---|
| length | Returns the number of items an array contains. |
| METHOD | DESCRIPTION |
|---|---|
| toLocaleString() | Returns the array items as strings, converted by the locale rules. |
| toString() | Returns the array items as strings. |
| valueOf() | Returns the array items as strings. |
| join() | Changes the separator / delimiter between array items. |
| METHOD | DESCRIPTION |
|---|---|
| push() | Adds given items to an array. |
| pop() | Removes the last added item from array. |
| METHOD | DESCRIPTION |
|---|---|
| shift() | Removes the first item added to an array. |
| unshift() | Adds given items to the front of an array. |
| METHOD | DESCRIPTION |
|---|---|
| reverse() | Reverses the order of items in an array. |
| sort() | Sorts items in acsending order, from smallest to largest. |
| METHOD | DESCRIPTION |
|---|---|
| concat() | Creates a new array based on the items from another existing array or arrays. |
| slice() | Creates an array that contains one or more items from another array. |
| splice() | Inserts new items into an existing array and / or deleting old items. |
Comments
No comments have been made yet.
Please login to leave a comment. Login now