Javascript Reference - JavaScript Array








The Javascript Array object stores multiple values in a single variable.

Array Properties

Property Description
length Sets or gets the number of elements in an array
prototype Array prototype to add properties and methods to an Array object

Array Methods

Method Description
concat() Adds two or more arrays together, and returns the joined arrays
indexOf() Find the first occurrence for an element in the array and returns its position
join() Return a string representation of the array by joining all elements into a string
lastIndexOf() Find the first occurrence for an element in the array from the end, and returns its position
pop() Removes the last element from the array, and returns that element. With this method we can use the Javascript Array as a stack.
push() Adds(pushed) new elements to the end of an array, and returns the new length. With this method we can use the Javascript Array as a stack.
reverse() Reverses the elements' order in an array
shift() Removes the first element of an array, and returns that element. With this method we can use the Javascript Array as a queue.
slice() Get the sub array from an array
sort() Sorts the elements in an array
splice() Adds/Removes/Replaces elements from an array
toString() Return a string representation of the array
unshift() Adds new elements to the beginning of an array, and returns the new length. With this method we can use Javascript Array as a reversed queue.
valueOf() Calling valueOf() method on Javascript Array returns the same result as calling toString() method on Array.
every() every() runs the given function on every item and returns true if the function returns true for every item.
filter() filter() runs the given function on every item and returns an array of all items for which the function returns true.
forEach() forEach() runs the given function on every item in the array. forEach() has no return value.
map() map() runs the given function on every item and returns the result of each function call in an array.
reduce() reduce() iterates all items and build up a value for return.
reduceRight() reduceRight() iterates all items and build up a value for return.
some() some() runs the given function on every item and returns true if the function returns true for any one item.
toLocaleString() Array toLocaleString() calls each item's toLocaleString() instead of toString() to get its string value.