Array : Object
Constructors
Creates an empty Array
(length
= 0). Can also be constructed as []
.
Example:
RunResults:
Creates an Array
with the specified parameters as the 0th, 1st, ... items of the Array
. Can also be constructed as [item0, item1, ...]
. See also Array.of()
.
Example:
RunResults:
Instance Indexers
Gets and sets the item in this
at index
. index
should be between 0
and this.length - 1
. If setting to an index greater than length - 1
, length
will be increased to index + 1
.
Example:
RunResults:
Instance Methods
Copies this[start], this[start + 1], ... this[end - 1]
to this[target], this[target + 1], ... this[target + start - end - 1]
. If end
is not specified, this.length
will be used. If end
is greater than this.length
, it is clamped to this.length
. Note, no elements are copied past this.length - 1
(ie, copyWithin()
will not increase the length of this
). Returns this
.
Example:
RunResults:
Returns true
if callback
returns true
for every item in this
. Otherwise returns false
. The Array
passed to callback
is the this
of the call to every
.
Example:
RunResults:
Fills this[start]
, this[start + 1]
, ... this[end - 1]
with value
. If end
is not specified, this.length
is used. Returns this
.
Example:
RunResults:
Returns a new Array
containing only the items in this
that callback
returned true
for. The Array
passed to callback
is the this
of the call to filter
.
Example:
RunResults:
Returns the first item in this
where callback
returns true
for that item. The Array
passed to callback
is the this
of the call to find
. See also findIndex()
.
Example:
RunResults:
Returns a new Array by flattening sub arrays into the array up to the specified depth
.
Example:
RunResults:
Calls callback
for each item in this
. The Array
passed to callback
is the this
of the call to forEach
.
Example:
RunResults:
Returns true
if item
is an element of this
starting the search from startingIndex
. If startingIndex
is negative, this.length
is added to it before starting the search.
Example:
RunResults:
Returns the first location of item
in this
starting the search from start
. If startingIndex
is negative, this.length
is added to it before starting the search. Returns -1
if item
is not found. See also findIndex()
and lastIndexOf()
.
Example:
RunResults:
Returns a String created by joining the toString()
of each item of this
separated by separator
.
Example:
RunResults:
Returns the location of item
by searchig backwards through this
, starting the search from startingIndex
. If startingIndex
is not specified, the search starts from the end of the array. If startingIndex
is negative, this.length
is added to it before starting the search. Returns -1
if item
is not found. See also indexOf()
.
Example:
RunResults:
Calls callback
for each item in this
in ascending order (0
to length-1
). It passes the return value of callback
for the i-1
th item as the previous
parameter for the i
th item. Returns the result from the last call to callback
. If initialValue
is not specified, callback
will first be called on this[1]
with previous
set to this[0]
. The Array
passed to callback
is the this
of the call to reduce
.
Example:
RunResults:
Calls callback
for each item in this
in descending order (length-1
to 0
). It passes the return value of callback
for the i+1
th item as the previous
parameter for the i
th item. Returns the result from the last call to callback
. If initialValue
is not specified, callback
will first be called on this[this.length - 2]
with previous
set to this[this.length - 1]
. The Array
passed to callback
is the this
of the call to reduceRight
.
Example:
RunResults:
Removes the first item of this
and shifts the remaining items down by 1
. Returns the removed item.
Example:
RunResults:
Returns a new Array
which is composed of the items this[start], this[start + 1], ..., this[end - 1]
. Note that item[end]
is not included. If start
or end
is negative, the value is added to this.length
before performing the slice. If end
is not specified, this.length
is used.
Example:
RunResults:
Returns true
if callback
returns true
for at least one item in this
. Otherwise returns false
. The Array
passed to callback
is the this
of the call to some
.
Example:
RunResults:
Sort the items of this
using comparisonFunction
to determine the sort order and returns this
. The Number returned by comparisonFunction
should be 0
if x
and y
are equal, negative if x
is less than y
, or positive if x
is greater than y
. If comparisonFunction
is not specified, the toString()
of the items will be sorted in alphanumeric order. Returns this
.
Example:
RunResults:
Removes count
items from this
starting at index start
. If the optional items
are specified, they are inserted into this
at start
. Returns a new Array
containing the removed items.
Example:
RunResults:
Inserts the specified items at the start of this
. Returns the new value of this.length
.
Example:
RunResults:
Returns an iterator of the items in this
. The values
function is also returned for this[Symbol.iterator]
so you can iterate over this
directly to get the values. See also entries()
and keys()
.
Example:
RunResults:
Array Methods
Creates an Array
with the specified parameters as the 0th, 1st, ... items of the Array
. Can also be constructed as [item0, item1, ...]
. Note that Array.of(x)
will always create an array of length 1
containing x
, while new Array(x)
will create an array of length x
if x
is an integer (and throw an exception if x
is a non-integer Number).