Available in Chrome 45+ | View on GitHub | Browse Samples
ECMAScript 2015 specification adds additional static methods on Array
and instance
methods on Array.prototype
.
The Array.from()
method converts an array-like object to a true
array. It takes an optional second parameter, which can be used to execute a map
function on each element of the array that is being created.
It comes in handy when dealing with the infamous NodeList
returned by document.querySelectorAll
.
The Array.of()
method creates a new Array
instance
with any number of arguments, regardless of their type.
The copyWithin()
method copies the sequence of array elements
within the array to the position starting at target
. The copy is
taken from the index positions of the second and third arguments
start
and end
. The end
argument is
optional and defaults to the length of the array.
If start
is negative, it will be treated as length+start
where length
is the length of the array. If end
is negative, it will be treated as length+end
.
The fill()
method fills all the elements of an array between an
optional start
index and an optional end
index with a
static value
.
The start
argument defaults to 0. The end
argument defaults to the length of the array.
The find()
method returns a value in the array, if at least one
element in the array satisfies the provided predicate
function. If
not, undefined
is returned. find()
does not mutate
the array on which it is called.
The findIndex()
method returns an index in the array, if at least
one element in the array satisfies the provided predicate
function. If not, -1 is returned. findIndex()
does not mutate the
array on which it is called.