Javascript Array Object

In Javascript Array Object is special type of object, it is used to store multiple values in a single variable.

The elements in a JavaScript array can have different data types, and they can be accessed by indexing. Javascript allows to array of array, elements of an array can also be arrays. In that case, the array is a multi-dimensional array. JavaScript allows associative arrays, too. In this type of arrays, each stored value is associated with a unique key, which can be used as an index. The unique keys are string types.

Here is the simple syntax to call properties and functions of Array Object.

Syntax

Array Properties

Here is a list of each array property with description.

PropertyDescription
constructor This will returns a reference to the array function that created the object.
index This property represents the zero-based index of the match in the string
input This property is only present in arrays created by regular expression matches.
length Reflects the number of elements in an array.
prototype The prototype property allows you to add properties and methods to an object.

Array Functions

Here is a list of each function of array object with description.

FunctionsDescription
concat() This will returns a new array comprised of this array joined with other array(s) and/or value(s).
every() This will returns true if every element in this array satisfies the provided testing function.
filter() This will creates a new array with all of the elements of this array for which the provided filtering function returns true.
forEach() Calls a function for each element in the array.
indexOf() This will returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.
join() This will joins all elements of an array into a string.
lastIndexOf() This will returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.
map() This will creates a new array with the results of calling a provided function on every element in this array.
pop() This will removes the last element from an array and returns that element.
push() This will adds one or more elements to the end of an array and returns the new length of the array.
reduce() This will apply a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.
reduceRight() This will apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
reverse() This will reverses the order of the elements of an array -- the first becomes the last, and the last becomes the first.
shift() This will removes the first element from an array and returns that element.
slice() This will extracts a section of an array and returns a new array.
some() This will returns true if at least one element in this array satisfies the provided testing function.
toSource() This will represents the source code of an object
sort() This will sorts the elements of an array.
splice() This will adds and/or removes elements from an array.
toString() This will returns a string representing the array and its elements.
unshift() This will adds one or more elements to the front of an array and returns the new length of the array.

Javascript Array Example