Javascript array

tutorial and example
tutorial and example

Array are used to represent the group of elements into a single unit or consecutive memory location.

Each and every element which is entering into the array is going to be stored in the array with the unique index starting from zero. Through the using of index we can store the data.

To declare an array in JavaScript we need to use new keyword. To create an array we use new Array(n).

Here n is number of slots in the array.

Syntax

NOTE: Whenever we create any array in JavaScript without specifying the size then we will create array object with the zero size.

Example

Try Now

Output

Example

Try Now

Functions used in Array

Functions Description
concat() To concat the element of one array at the end of another array and returns array.
sort() Sort all elements of an array.
reverse() Reverse all the elements.
slice() To extract specified number of elements starting from specified index without deleting them from array.
splice() To extract specified number of elements starting from specified index and delete them from array.
push() Push all the elements in array to top.
pop() Pop the top elements from array.