Arrays in Javascript

Arrays are useful way to store information and is a prominent data structure in all programming languages.
There are many ways to create javascript arrays as in the examples below. By default the javascript arrays start from index 0.

Example 1: Javscript Arrays

rollnumbers = new Array(11, 22,33,44,55);

Example 2: Javscript Arrays

Example 3: Javscript Arrays

Example 4: Printing Javscript Arrays

To print the value in the javascript array, you can access the value by the integer key. Example:

This would generate the alert 55.

Methods Of Array Object

Many operations can be performed with Arrays.There are many pre-defined functions or methods of array object.Here is a list of them.

Method Operation
Concat It adds one array to another array.
Pop It removes one element of the array.
Push It adds one element in the array.
Slice It slices a section of the array.
Splice It adds one element to the specified position.
Sort It converts array into either ascending or descending order.
toString It converts an array to string.