Class Array

An Array of items.

PropertyDescription
length: NumberThe length of the Array.
ConstructorDescription
Array()Constructs an Array.
Array(Number)Constructs an Array of the specified length.
Array(Object...)Constructs an Array using the specified values.
MethodDescription
concat(Object...)Constructs an Array by concatenating multiple values.
copyWithin(Number, Number, Number)Copies elements within this array.
entries()Returns an iterator containing all index/value pairs of this array.
every(Function)Returns true if every element in this array satisfies the test performed in the callback function.
every(Function, Object)Returns true if every element in the thisObject argument satisfies the test performed in the callback function, false otherwise.
fill(Object, Number, Number)Sets multiple entries of this array to specific value.
filter(Function)Returns a new Array with all of the elements that pass the test implemented by the callback function.
filter(Function, Object)Returns a new Array with all of the elements that pass the test implemented by the callback function that is run against the specified Array, thisObject.
find(Function, Object)Returns the first value within the array that satisfies the test defined in the callback function.
findIndex(Function, Object)Returns the index of the first value within the array that satisfies the test defined in the callback function.
forEach(Function)Runs the provided callback function once for each element present in the Array.
forEach(Function, Object)Runs the provided callback function once for each element present in the specified Array, thisObject.
static from(Object, Function, Object)Creates a new array from an array-like object or an Iterable.
includes(Object, Number)Returns if the array contains a specific value.
indexOf(Object)Returns the first index at which a given element can be found in the array, or -1 if it is not present.
indexOf(Object, Number)Returns the first index at which a given element can be found in the array starting at fromIndex, or -1 if it is not present.
static isArray(Object)Checks if the passed object is an array.
join()Converts all Array elements to Strings and concatenates them.
join(String)Converts all array elements to Strings and concatenates them.
keys()Returns an iterator containing all indexes of this array.
lastIndexOf(Object)Returns the last index at which a given element can be found in the array, or -1 if it is not present.
lastIndexOf(Object, Number)Returns the last index at which a given element can be found in the array starting at fromIndex, or -1 if it is not present.
map(Function)Creates a new Array with the results of calling the specified function on every element in this Array.
map(Function, Object)Creates a new Array with the results of calling the specified function on every element in the specified Array.
static of(Object...)Creates a new array from a variable list of elements.
pop()Removes and returns the last element of the Array.
push(Object...)Appends elements to the Array.
reverse()Reverses the order of the elements in the Array.
shift()Shifts elements down in the Array and returns the former first element.
slice(Number, Number)Returns a new Array containing a portion of the Array using the specified start and end positions.
some(Function)Returns true if any of the elements in the Array pass the test defined in the callback function, false otherwise.
some(Function, Object)Returns true if any of the elements in the specified Array pass the test defined in the callback function, false otherwise.
sort()Sorts the elements of the Array in alphabetical order based on character encoding.
sort(Function)Sorts the elements of the Array in alphabetical order based on character encoding.
splice(Number, Number, Object...)Deletes the specified number of elements from the Array at the specified position, and then inserts values into the Array at that location.
toLocaleString()Converts the Array to a localized String.
toString()Converts the Array to a String.
unshift(Object...)Inserts elements at the beginning of the Array.
values()Returns an iterator containing all values of this array.

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

length: Number

The length of the Array.


Array()

Constructs an Array.


Array(length: Number)

Constructs an Array of the specified length.

Parameters:

  • length - the length of the Array.

Array(values: Object...)

Constructs an Array using the specified values.

Parameters:

  • values - zero or more values that are stored in the Array.

concat(values: Object...): Array

Constructs an Array by concatenating multiple values.

Parameters:

  • values - one or more Array values.

Returns:

  • a new Array containing the concatenated values.

copyWithin(target: Number, start: Number, end: Number): Array

Copies elements within this array. The array length is not changed.

Parameters:

  • target - The target of the first element to copy.
  • start - Optional. The first index to copy. Default is 0.
  • end - Optional. The index of the end. This element is not included. Default is copy all to the array end.

Returns:

  • This array.

API Version:

Available from version 21.2.


entries(): ES6Iterator

Returns an iterator containing all index/value pairs of this array. The iterator produces a series of two-element arrays with the first element as the index and the second element as the value.

API Version:

Available from version 21.2.


every(callback: Function): Boolean

Returns true if every element in this array satisfies the test performed in the callback function. The callback function is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

Parameters:

  • callback - the function to call to determine if every element in this array satisfies the test defined by the function. The callback function is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

Returns:

  • true if every element in this array satisfies the test performed in the callback function.

See Also:


every(callback: Function, thisObject: Object): Boolean

Returns true if every element in the thisObject argument satisfies the test performed in the callback function, false otherwise. The callback function is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

Parameters:

  • callback - the function to call to determine if every element in this array satisfies the test defined by the function. The callback function is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
  • thisObject - the Object to use as 'this' when executing callback.

Returns:

  • true if every element in thisObject satisfies the test performed in the callback function, false otherwise.

See Also:


fill(value: Object, start: Number, end: Number): Array

Sets multiple entries of this array to specific value.

Parameters:

  • value - The value to set.
  • start - Optional. The first index to copy. Default is 0.
  • end - Optional. The index of the end. This element is not included. Default is copy all to the array end.

Returns:

  • This array.

API Version:

Available from version 21.2.


filter(callback: Function): Array

Returns a new Array with all of the elements that pass the test implemented by the callback function. The callback function is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

Parameters:

  • callback - the function that is called on this Array and which returns a new Array containing the elements that satisfy the function's test. The callback function is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

Returns:

  • a new Array containing the elements that satisfy the function's test.

filter(callback: Function, thisObject: Object): Array

Returns a new Array with all of the elements that pass the test implemented by the callback function that is run against the specified Array, thisObject. The callback function is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

Parameters:

  • callback - the function that is called on the thisObject Array and which returns a new Array containing the elements that satisfy the function's test. The callback function is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
  • thisObject - the Object to use as 'this' when executing callback.

Returns:

  • a new Array containing the elements that satisfy the function's test.

find(callback: Function, thisObject: Object): Object

Returns the first value within the array that satisfies the test defined in the callback function.

Parameters:

  • callback - The function to call, which is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
  • thisObject - The object to use as 'this' when executing callback.

Returns:

  • The first value within the array that satisfies the test defined in the callback function, undefined if no matching value was found.

API Version:

Available from version 21.2.


findIndex(callback: Function, thisObject: Object): Number

Returns the index of the first value within the array that satisfies the test defined in the callback function.

Parameters:

  • callback - The function to call, which is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
  • thisObject - The object to use as 'this' when executing callback.

Returns:

  • The index of the first value within the array that satisfies the test defined in the callback function, -1 if no matching value was found.

API Version:

Available from version 21.2.


forEach(callback: Function): void

Runs the provided callback function once for each element present in the Array. The callback function is invoked only for indexes of the Array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned a value.

Parameters:

  • callback - the function to call, which is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

forEach(callback: Function, thisObject: Object): void

Runs the provided callback function once for each element present in the specified Array, thisObject. The callback function is invoked only for indexes of the Array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned a value.

Parameters:

  • callback - the function to call, which is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
  • thisObject - the Object to use as 'this' when executing callback.

static from(arrayLike: Object, mapFn: Function, thisObject: Object): Array

Creates a new array from an array-like object or an Iterable.

Parameters:

  • arrayLike - An array-like object or an iterable that provides the elements for the new array.
  • mapFn - Optional. A function that maps the input elements into the value for the new array.
  • thisObject - Optional. The Object to use as 'this' when executing mapFn.

Returns:

  • The newly created array.

API Version:

Available from version 21.2.


includes(valueToFind: Object, fromIndex: Number): Boolean

Returns if the array contains a specific value.

Parameters:

  • valueToFind - The value to look for.
  • fromIndex - Optional. The index to start from.

Returns:

  • true if the value is found in the array else false.

API Version:

Available from version 21.2.


indexOf(elementToLocate: Object): Number

Returns the first index at which a given element can be found in the array, or -1 if it is not present.

Parameters:

  • elementToLocate - the element to locate in the Array.

Returns:

  • the index of the element or -1 if it is no preset.

indexOf(elementToLocate: Object, fromIndex: Number): Number

Returns the first index at which a given element can be found in the array starting at fromIndex, or -1 if it is not present.

Parameters:

  • elementToLocate - the element to locate in the Array.
  • fromIndex - the index from which to start looking for the element.

Returns:

  • the index of the element or -1 if it is no preset.

static isArray(object: Object): Boolean

Checks if the passed object is an array.

Parameters:

  • object - The object to ckeck.

Returns:

  • true if the passed object is an array else false.

join(): String

Converts all Array elements to Strings and concatenates them.

Returns:

  • a concatenated list of all Array elements as a String.

join(separator: String): String

Converts all array elements to Strings and concatenates them.

Parameters:

  • separator - an optional character or string used to separate one element of the Array from the next element in the return String.

Returns:

  • a concatenated list of all Array elements as a String where the specified delimiter is used to separate elements.

keys(): ES6Iterator

Returns an iterator containing all indexes of this array.

API Version:

Available from version 21.2.


lastIndexOf(elementToLocate: Object): Number

Returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards.

Parameters:

  • elementToLocate - the element to locate in the Array.

Returns:

  • the index of the element or -1 if it is no preset.

lastIndexOf(elementToLocate: Object, fromIndex: Number): Number

Returns the last index at which a given element can be found in the array starting at fromIndex, or -1 if it is not present. The array is searched backwards.

Parameters:

  • elementToLocate - the element to locate in the Array.
  • fromIndex - the index from which to start looking for the element. The array is searched backwards.

Returns:

  • the index of the element or -1 if it is no present.

map(callback: Function): Array

Creates a new Array with the results of calling the specified function on every element in this Array. The callback function is invoked only for indexes of the Array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.

Parameters:

  • callback - the function to call, which is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

Returns:

  • a new Array with the results of calling the specified function on every element in this Array.

map(callback: Function, thisObject: Object): Array

Creates a new Array with the results of calling the specified function on every element in the specified Array. The callback function is invoked only for indexes of the Array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values.

Parameters:

  • callback - the function to call, which is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
  • thisObject - the Object to use as 'this' when executing callback.

Returns:

  • a new Array with the results of calling the specified function on every element in this Array.

static of(values: Object...): Array

Creates a new array from a variable list of elements.

Parameters:

  • values - The array values.

Returns:

  • The newly created array.

API Version:

Available from version 21.2.


pop(): Object

Removes and returns the last element of the Array.

Returns:

  • the last element of the Array.

push(values: Object...): Number

Appends elements to the Array.

Parameters:

  • values - one or more values that will be appended to the Array.

Returns:

  • the new length of the Array.

reverse(): void

Reverses the order of the elements in the Array.


shift(): Object

Shifts elements down in the Array and returns the former first element.

Returns:

  • the former first element.

slice(start: Number, end: Number): Array

Returns a new Array containing a portion of the Array using the specified start and end positions.

Parameters:

  • start - the location in the Array to start the slice operation.
  • end - the location in the Array to stop the slice operation.

Returns:

  • a new Array containing the members bound by start and end.

some(callback: Function): Boolean

Returns true if any of the elements in the Array pass the test defined in the callback function, false otherwise.

Parameters:

  • callback - the function to call, which is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.

Returns:

  • true if any of the elements in the Array pass the test defined in the callback function, false otherwise.

some(callback: Function, thisObject: Object): Boolean

Returns true if any of the elements in the specified Array pass the test defined in the callback function, false otherwise.

Parameters:

  • callback - the function to call, which is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.
  • thisObject - the Object to use as 'this' when executing callback.

Returns:

  • true if any of the elements in the Array pass the test defined in the callback function, false otherwise.

sort(): Array

Sorts the elements of the Array in alphabetical order based on character encoding.

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

Returns:

  • a reference to the Array.

sort(function: Function): Array

Sorts the elements of the Array in alphabetical order based on character encoding.

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

Parameters:

  • function - a Function used to specify the sorting order.

Returns:

  • a reference to the Array.

See Also:


splice(start: Number, deleteCount: Number, values: Object...): Array

Deletes the specified number of elements from the Array at the specified position, and then inserts values into the Array at that location.

Parameters:

  • start - the start location.
  • deleteCount - the number of items to delete.
  • values - zero or more values to be inserted into the Array.

toLocaleString(): String

Converts the Array to a localized String.

Returns:

  • a localized String representing the Array.

toString(): String

Converts the Array to a String.

Returns:

  • a String representation of the Array.

unshift(values: Object...): Number

Inserts elements at the beginning of the Array.

Parameters:

  • values - one or more vales that will be inserted into the beginning of the Array.

Returns:

  • the new length of the Array.

values(): ES6Iterator

Returns an iterator containing all values of this array.

API Version:

Available from version 21.2.