23.1 Array Objects
Array objects are exotic objects that give special treatment to a certain class of property names. See
23.1.1 The Array Constructor
The Array
 is %Array%.
 is the initial value of the
"Array" property of theglobal object .  creates and initializes a new
Array exotic object when called as aconstructor .  also creates and initializes a new Array object when called as a function rather than as a
constructor . Thus the function callArray(…)
is equivalent to the object creation expressionnew Array(…)
with the same arguments.  is a function whose behaviour differs based upon the number and types of its arguments.
 is designed to be subclassable. It may be used as the value of an
extends
clause of a class definition. Subclass constructors that intend to inherit the exotic Array behaviour must include asuper
call to the Arrayconstructor to initialize subclass instances that are Array exotic objects. However, most of theArray.prototype
methods are generic methods that are not dependent upon theirthis value being anArray exotic object .  has a
"length" property whose value is1 _{𝔽}.
23.1.1.1 Array ( ...values )
When the Array
function is called, the following steps are taken:
 If NewTarget is
undefined , let newTarget be theactive function object ; else let newTarget be NewTarget.  Let proto be ?
GetPrototypeFromConstructor (newTarget,"%Array.prototype%" ).  Let numberOfArgs be the number of elements in values.
 If numberOfArgs = 0, then
 Return !
ArrayCreate (0, proto).
 Return !
 Else if numberOfArgs = 1, then
 Let len be values[0].
 Let array be !
ArrayCreate (0, proto).  If
Type (len) is not Number, then Perform !
CreateDataPropertyOrThrow (array,"0" , len).  Let intLen be
1 _{𝔽}.
 Perform !
 Else,
 Let intLen be !
ToUint32 (len).  If intLen is not the same value as len, throw a
RangeError exception.
 Let intLen be !
 Perform !
Set (array,"length" , intLen,true ).  Return array.
 Else,
Assert : numberOfArgs ≥ 2. Let array be ?
ArrayCreate (numberOfArgs, proto).  Let k be 0.
 Repeat, while k < numberOfArgs,
 Let Pk be !
ToString (𝔽 (k)).  Let itemK be values[k].
 Perform !
CreateDataPropertyOrThrow (array, Pk, itemK).  Set k to k + 1.
 Let Pk be !
Assert : Themathematical value of array's"length" property is numberOfArgs. Return array.
23.1.2 Properties of the Array Constructor
The Array
 has a [[Prototype]] internal slot whose value is
%Function.prototype% .  has the following properties:
23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
When the from
method is called with argument items and optional arguments mapfn and thisArg, the following steps are taken:
 Let C be the
this value.  If mapfn is
undefined , let mapping befalse .  Else,
 If
IsCallable (mapfn) isfalse , throw aTypeError exception.  Let mapping be
true .
 If
 Let usingIterator be ?
GetMethod (items,@@iterator ).  If usingIterator is not
undefined , then If
IsConstructor (C) istrue , then Let A be ?
Construct (C).
 Let A be ?
 Else,
 Let A be !
ArrayCreate (0).
 Let A be !
 Let iteratorRecord be ?
GetIterator (items,sync , usingIterator).  Let k be 0.
 Repeat,
 If k ≥ 2^{53}  1, then
 Let error be
ThrowCompletion (a newly createdTypeError object).  Return ?
IteratorClose (iteratorRecord, error).
 Let error be
 Let Pk be !
ToString (𝔽 (k)).  Let next be ?
IteratorStep (iteratorRecord).  If next is
false , then  Let nextValue be ?
IteratorValue (next).  If mapping is
true , then Let mappedValue be
Call (mapfn, thisArg, « nextValue,𝔽 (k) »).  If mappedValue is an
abrupt completion , return ?IteratorClose (iteratorRecord, mappedValue).  Set mappedValue to mappedValue.[[Value]].
 Let mappedValue be
 Else, let mappedValue be nextValue.
 Let defineStatus be
CreateDataPropertyOrThrow (A, Pk, mappedValue).  If defineStatus is an
abrupt completion , return ?IteratorClose (iteratorRecord, defineStatus).  Set k to k + 1.
 If k ≥ 2^{53}  1, then
 If
 NOTE: items is not an Iterable so assume it is an
arraylike object .  Let arrayLike be !
ToObject (items).  Let len be ?
LengthOfArrayLike (arrayLike).  If
IsConstructor (C) istrue , then  Else,
 Let A be ?
ArrayCreate (len).
 Let A be ?
 Let k be 0.
 Repeat, while k < len,
 Perform ?
Set (A,"length" ,𝔽 (len),true ).  Return A.
The from
function is an intentionally generic factory method; it does not require that its
23.1.2.2 Array.isArray ( arg )
The isArray
function takes one argument arg, and performs the following steps:
 Return ?
IsArray (arg).
23.1.2.3 Array.of ( ...items )
When the of
method is called with any number of arguments, the following steps are taken:
 Let len be the number of elements in items.
 Let lenNumber be
𝔽 (len).  Let C be the
this value.  If
IsConstructor (C) istrue , then Let A be ?
Construct (C, « lenNumber »).
 Let A be ?
 Else,
 Let A be ?
ArrayCreate (len).
 Let A be ?
 Let k be 0.
 Repeat, while k < len,
 Let kValue be items[k].
 Let Pk be !
ToString (𝔽 (k)).  Perform ?
CreateDataPropertyOrThrow (A, Pk, kValue).  Set k to k + 1.
 Perform ?
Set (A,"length" , lenNumber,true ).  Return A.
The of
function is an intentionally generic factory method; it does not require that its
23.1.2.4 Array.prototype
The value of Array.prototype
is the
This property has the attributes { [[Writable]]:
23.1.2.5 get Array [ @@species ]
Array[@@species]
is an
 Return the
this value.
The value of the
Array prototype methods normally use their
23.1.3 Properties of the Array Prototype Object
The Array prototype object:
 is %Array.prototype%.
 is an
Array exotic object and has the internal methods specified for such objects.  has a
"length" property whose initial value is+0 _{𝔽} and whose attributes are { [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }.  has a [[Prototype]] internal slot whose value is
%Object.prototype% .
The Array prototype object is specified to be an
23.1.3.1 Array.prototype.concat ( ...items )
When the concat
method is called with zero or more arguments, it returns an array containing the array elements of the object followed by the array elements of each argument.
The following steps are taken:
 Let O be ?
ToObject (this value).  Let A be ?
ArraySpeciesCreate (O, 0).  Let n be 0.
 Prepend O to items.
 For each element E of items, do
 Let spreadable be ?
IsConcatSpreadable (E).  If spreadable is
true , then Let k be 0.
 Let len be ?
LengthOfArrayLike (E).  If n + len > 2^{53}  1, throw a
TypeError exception.  Repeat, while k < len,
 Let P be !
ToString (𝔽 (k)).  Let exists be ?
HasProperty (E, P).  If exists is
true , then Let subElement be ?
Get (E, P).  Perform ?
CreateDataPropertyOrThrow (A, !ToString (𝔽 (n)), subElement).
 Let subElement be ?
 Set n to n + 1.
 Set k to k + 1.
 Let P be !
 Else,
 NOTE: E is added as a single item rather than spread.
 If n ≥ 2^{53}  1, throw a
TypeError exception.  Perform ?
CreateDataPropertyOrThrow (A, !ToString (𝔽 (n)), E).  Set n to n + 1.
 Let spreadable be ?
 Perform ?
Set (A,"length" ,𝔽 (n),true ).  Return A.
The concat
method is
The explicit setting of the
The concat
function is intentionally generic; it does not require that its
23.1.3.1.1 IsConcatSpreadable ( O )
The abstract operation IsConcatSpreadable takes argument O. It performs the following steps when called:
 If
Type (O) is not Object, returnfalse .  Let spreadable be ?
Get (O,@@isConcatSpreadable ).  If spreadable is not
undefined , return !ToBoolean (spreadable).  Return ?
IsArray (O).
23.1.3.2 Array.prototype.constructor
The initial value of Array.prototype.constructor
is
23.1.3.3 Array.prototype.copyWithin ( target, start [ , end ] )
The copyWithin
method takes up to three arguments target, start and end.
The end argument is optional with the length of the
The following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  Let relativeTarget be ?
ToIntegerOrInfinity (target).  If relativeTarget is ∞, let to be 0.
 Else if relativeTarget < 0, let to be
max (len + relativeTarget, 0).  Else, let to be
min (relativeTarget, len).  Let relativeStart be ?
ToIntegerOrInfinity (start).  If relativeStart is ∞, let from be 0.
 Else if relativeStart < 0, let from be
max (len + relativeStart, 0).  Else, let from be
min (relativeStart, len).  If end is
undefined , let relativeEnd be len; else let relativeEnd be ?ToIntegerOrInfinity (end).  If relativeEnd is ∞, let final be 0.
 Else if relativeEnd < 0, let final be
max (len + relativeEnd, 0).  Else, let final be
min (relativeEnd, len).  Let count be
min (final  from, len  to).  If from < to and to < from + count, then
 Let direction be 1.
 Set from to from + count  1.
 Set to to to + count  1.
 Else,
 Let direction be 1.
 Repeat, while count > 0,
 Let fromKey be !
ToString (𝔽 (from)).  Let toKey be !
ToString (𝔽 (to)).  Let fromPresent be ?
HasProperty (O, fromKey).  If fromPresent is
true , then  Else,
Assert : fromPresent isfalse . Perform ?
DeletePropertyOrThrow (O, toKey).
 Set from to from + direction.
 Set to to to + direction.
 Set count to count  1.
 Let fromKey be !
 Return O.
The copyWithin
function is intentionally generic; it does not require that its
23.1.3.4 Array.prototype.entries ( )
The following steps are taken:
 Let O be ?
ToObject (this value).  Return
CreateArrayIterator (O,key+value ).
23.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] )
callbackfn should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. every
calls callbackfn once for each element present in the array, in ascending order, until it finds one where callbackfn returns every
immediately returns every
will return
If a thisArg parameter is provided, it will be used as the
callbackfn is called with three arguments: the value of the element, the index of the element, and the object being traversed.
every
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.
The range of elements processed by every
is set before the first call to callbackfn. Elements which are appended to the array after the call to every
begins will not be visited by callbackfn. If existing elements of the array are changed, their value as passed to callbackfn will be the value at the time every
visits them; elements that are deleted after the call to every
begins and before being visited are not visited. every
acts like the "for all" quantifier in mathematics. In particular, for an empty array, it returns
When the every
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (callbackfn) isfalse , throw aTypeError exception.  Let k be 0.
 Repeat, while k < len,
 Return
true .
The every
function is intentionally generic; it does not require that its
23.1.3.6 Array.prototype.fill ( value [ , start [ , end ] ] )
The fill
method takes up to three arguments value, start and end.
The start and end arguments are optional with default values of 0 and the length of the
The following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  Let relativeStart be ?
ToIntegerOrInfinity (start).  If relativeStart is ∞, let k be 0.
 Else if relativeStart < 0, let k be
max (len + relativeStart, 0).  Else, let k be
min (relativeStart, len).  If end is
undefined , let relativeEnd be len; else let relativeEnd be ?ToIntegerOrInfinity (end).  If relativeEnd is ∞, let final be 0.
 Else if relativeEnd < 0, let final be
max (len + relativeEnd, 0).  Else, let final be
min (relativeEnd, len).  Repeat, while k < final,
 Return O.
The fill
function is intentionally generic; it does not require that its
23.1.3.7 Array.prototype.filter ( callbackfn [ , thisArg ] )
callbackfn should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. filter
calls callbackfn once for each element in the array, in ascending order, and constructs a new array of all the values for which callbackfn returns
If a thisArg parameter is provided, it will be used as the
callbackfn is called with three arguments: the value of the element, the index of the element, and the object being traversed.
filter
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.
The range of elements processed by filter
is set before the first call to callbackfn. Elements which are appended to the array after the call to filter
begins will not be visited by callbackfn. If existing elements of the array are changed their value as passed to callbackfn will be the value at the time filter
visits them; elements that are deleted after the call to filter
begins and before being visited are not visited.
When the filter
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (callbackfn) isfalse , throw aTypeError exception.  Let A be ?
ArraySpeciesCreate (O, 0).  Let k be 0.
 Let to be 0.
 Repeat, while k < len,
 Let Pk be !
ToString (𝔽 (k)).  Let kPresent be ?
HasProperty (O, Pk).  If kPresent is
true , then  Set k to k + 1.
 Let Pk be !
 Return A.
The filter
function is intentionally generic; it does not require that its
23.1.3.8 Array.prototype.find ( predicate [ , thisArg ] )
The find
method is called with one or two arguments, predicate and thisArg.
predicate should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. find
calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns find
immediately returns that element value. Otherwise, find
returns
If a thisArg parameter is provided, it will be used as the
predicate is called with three arguments: the value of the element, the index of the element, and the object being traversed.
find
does not directly mutate the object on which it is called but the object may be mutated by the calls to predicate.
The range of elements processed by find
is set before the first call to predicate. Elements that are appended to the array after the call to find
begins will not be visited by predicate. If existing elements of the array are changed, their value as passed to predicate will be the value at the time that find
visits them; elements that are deleted after the call to find
begins and before being visited are not visited.
When the find
method is called, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (predicate) isfalse , throw aTypeError exception.  Let k be 0.
 Repeat, while k < len,
 Return
undefined .
The find
function is intentionally generic; it does not require that its
23.1.3.9 Array.prototype.findIndex ( predicate [ , thisArg ] )
predicate should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. findIndex
calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns findIndex
immediately returns the index of that element value. Otherwise, findIndex
returns 1.
If a thisArg parameter is provided, it will be used as the
predicate is called with three arguments: the value of the element, the index of the element, and the object being traversed.
findIndex
does not directly mutate the object on which it is called but the object may be mutated by the calls to predicate.
The range of elements processed by findIndex
is set before the first call to predicate. Elements that are appended to the array after the call to findIndex
begins will not be visited by predicate. If existing elements of the array are changed, their value as passed to predicate will be the value at the time that findIndex
visits them; elements that are deleted after the call to findIndex
begins and before being visited are not visited.
When the findIndex
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (predicate) isfalse , throw aTypeError exception.  Let k be 0.
 Repeat, while k < len,
 Return
1 _{𝔽}.
The findIndex
function is intentionally generic; it does not require that its
23.1.3.10 Array.prototype.flat ( [ depth ] )
When the flat
method is called with zero or one arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let sourceLen be ?
LengthOfArrayLike (O).  Let depthNum be 1.
 If depth is not
undefined , then Set depthNum to ?
ToIntegerOrInfinity (depth).  If depthNum < 0, set depthNum to 0.
 Set depthNum to ?
 Let A be ?
ArraySpeciesCreate (O, 0).  Perform ?
FlattenIntoArray (A, O, sourceLen, 0, depthNum).  Return A.
23.1.3.10.1 FlattenIntoArray ( target, source, sourceLen, start, depth [ , mapperFunction, thisArg ] )
The abstract operation FlattenIntoArray takes arguments target, source, sourceLen (a nonnegative
Assert :Type (target) is Object.Assert :Type (source) is Object.Assert : If mapperFunction is present, then !IsCallable (mapperFunction) istrue , thisArg is present, and depth is 1. Let targetIndex be start.
 Let sourceIndex be
+0 _{𝔽}.  Repeat, while
ℝ (sourceIndex) < sourceLen, Let P be !
ToString (sourceIndex).  Let exists be ?
HasProperty (source, P).  If exists is
true , then Let element be ?
Get (source, P).  If mapperFunction is present, then
 Set element to ?
Call (mapperFunction, thisArg, « element, sourceIndex, source »).
 Set element to ?
 Let shouldFlatten be
false .  If depth > 0, then
 Set shouldFlatten to ?
IsArray (element).
 Set shouldFlatten to ?
 If shouldFlatten is
true , then If depth is +∞, let newDepth be +∞.
 Else, let newDepth be depth  1.
 Let elementLen be ?
LengthOfArrayLike (element).  Set targetIndex to ?
FlattenIntoArray (target, element, elementLen, targetIndex, newDepth).
 Else,
 If targetIndex ≥ 2^{53}  1, throw a
TypeError exception.  Perform ?
CreateDataPropertyOrThrow (target, !ToString (𝔽 (targetIndex)), element).  Set targetIndex to targetIndex + 1.
 If targetIndex ≥ 2^{53}  1, throw a
 Let element be ?
 Set sourceIndex to sourceIndex +
1 _{𝔽}.
 Let P be !
 Return targetIndex.
23.1.3.11 Array.prototype.flatMap ( mapperFunction [ , thisArg ] )
When the flatMap
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let sourceLen be ?
LengthOfArrayLike (O).  If !
IsCallable (mapperFunction) isfalse , throw aTypeError exception.  Let A be ?
ArraySpeciesCreate (O, 0).  Perform ?
FlattenIntoArray (A, O, sourceLen, 0, 1, mapperFunction, thisArg).  Return A.
23.1.3.12 Array.prototype.forEach ( callbackfn [ , thisArg ] )
callbackfn should be a function that accepts three arguments. forEach
calls callbackfn once for each element present in the array, in ascending order. callbackfn is called only for elements of the array which actually exist; it is not called for missing elements of the array.
If a thisArg parameter is provided, it will be used as the
callbackfn is called with three arguments: the value of the element, the index of the element, and the object being traversed.
forEach
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.
The range of elements processed by forEach
is set before the first call to callbackfn. Elements which are appended to the array after the call to forEach
begins will not be visited by callbackfn. If existing elements of the array are changed, their value as passed to callbackfn will be the value at the time forEach
visits them; elements that are deleted after the call to forEach
begins and before being visited are not visited.
When the forEach
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (callbackfn) isfalse , throw aTypeError exception.  Let k be 0.
 Repeat, while k < len,
 Return
undefined .
The forEach
function is intentionally generic; it does not require that its
23.1.3.13 Array.prototype.includes ( searchElement [ , fromIndex ] )
includes
compares searchElement to the elements of the array, in ascending order, using the
The optional second argument fromIndex defaults to
When the includes
method is called, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If len is 0, return
false .  Let n be ?
ToIntegerOrInfinity (fromIndex). Assert : If fromIndex isundefined , then n is 0. If n is +∞, return
false .  Else if n is ∞, set n to 0.
 If n ≥ 0, then
 Let k be n.
 Else,
 Let k be len + n.
 If k < 0, set k to 0.
 Repeat, while k < len,
 Let elementK be ?
Get (O, !ToString (𝔽 (k))).  If
SameValueZero (searchElement, elementK) istrue , returntrue .  Set k to k + 1.
 Let elementK be ?
 Return
false .
The includes
function is intentionally generic; it does not require that its
The includes
method intentionally differs from the similar indexOf
method in two ways. First, it uses the
23.1.3.14 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
indexOf
compares searchElement to the elements of the array, in ascending order, using the
The optional second argument fromIndex defaults to
When the indexOf
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If len is 0, return
1 _{𝔽}.  Let n be ?
ToIntegerOrInfinity (fromIndex). Assert : If fromIndex isundefined , then n is 0. If n is +∞, return
1 _{𝔽}.  Else if n is ∞, set n to 0.
 If n ≥ 0, then
 Let k be n.
 Else,
 Let k be len + n.
 If k < 0, set k to 0.
 Repeat, while k < len,
 Let kPresent be ?
HasProperty (O, !ToString (𝔽 (k))).  If kPresent is
true , then Let elementK be ?
Get (O, !ToString (𝔽 (k))).  Let same be the result of performing
Strict Equality Comparison searchElement === elementK.  If same is
true , return𝔽 (k).
 Let elementK be ?
 Set k to k + 1.
 Let kPresent be ?
 Return
1 _{𝔽}.
The indexOf
function is intentionally generic; it does not require that its
23.1.3.15 Array.prototype.join ( separator )
The elements of the array are converted to Strings, and these Strings are then concatenated, separated by occurrences of the separator. If no separator is provided, a single comma is used as the separator.
The join
method takes one argument, separator, and performs the following steps:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If separator is
undefined , let sep be the singleelement String"," .  Else, let sep be ?
ToString (separator).  Let R be the empty String.
 Let k be 0.
 Repeat, while k < len,
 If k > 0, set R to the
stringconcatenation of R and sep.  Let element be ?
Get (O, !ToString (𝔽 (k))).  If element is
undefined ornull , let next be the empty String; otherwise, let next be ?ToString (element).  Set R to the
stringconcatenation of R and next.  Set k to k + 1.
 If k > 0, set R to the
 Return R.
The join
function is intentionally generic; it does not require that its
23.1.3.16 Array.prototype.keys ( )
The following steps are taken:
 Let O be ?
ToObject (this value).  Return
CreateArrayIterator (O,key ).
23.1.3.17 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
lastIndexOf
compares searchElement to the elements of the array in descending order using the
The optional second argument fromIndex defaults to the array's length minus one (i.e. the whole array is searched). If it is greater than or equal to the length of the array, the whole array will be searched. If it is less than
When the lastIndexOf
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If len is 0, return
1 _{𝔽}.  If fromIndex is present, let n be ?
ToIntegerOrInfinity (fromIndex); else let n be len  1.  If n is ∞, return
1 _{𝔽}.  If n ≥ 0, then
 Let k be
min (n, len  1).
 Let k be
 Else,
 Let k be len + n.
 Repeat, while k ≥ 0,
 Let kPresent be ?
HasProperty (O, !ToString (𝔽 (k))).  If kPresent is
true , then Let elementK be ?
Get (O, !ToString (𝔽 (k))).  Let same be the result of performing
Strict Equality Comparison searchElement === elementK.  If same is
true , return𝔽 (k).
 Let elementK be ?
 Set k to k  1.
 Let kPresent be ?
 Return
1 _{𝔽}.
The lastIndexOf
function is intentionally generic; it does not require that its
23.1.3.18 Array.prototype.map ( callbackfn [ , thisArg ] )
callbackfn should be a function that accepts three arguments. map
calls callbackfn once for each element in the array, in ascending order, and constructs a new Array from the results. callbackfn is called only for elements of the array which actually exist; it is not called for missing elements of the array.
If a thisArg parameter is provided, it will be used as the
callbackfn is called with three arguments: the value of the element, the index of the element, and the object being traversed.
map
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.
The range of elements processed by map
is set before the first call to callbackfn. Elements which are appended to the array after the call to map
begins will not be visited by callbackfn. If existing elements of the array are changed, their value as passed to callbackfn will be the value at the time map
visits them; elements that are deleted after the call to map
begins and before being visited are not visited.
When the map
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (callbackfn) isfalse , throw aTypeError exception.  Let A be ?
ArraySpeciesCreate (O, len).  Let k be 0.
 Repeat, while k < len,
 Let Pk be !
ToString (𝔽 (k)).  Let kPresent be ?
HasProperty (O, Pk).  If kPresent is
true , then Let kValue be ?
Get (O, Pk).  Let mappedValue be ?
Call (callbackfn, thisArg, « kValue,𝔽 (k), O »).  Perform ?
CreateDataPropertyOrThrow (A, Pk, mappedValue).
 Let kValue be ?
 Set k to k + 1.
 Let Pk be !
 Return A.
The map
function is intentionally generic; it does not require that its
23.1.3.19 Array.prototype.pop ( )
The last element of the array is removed from the array and returned.
When the pop
method is called, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If len = 0, then
 Perform ?
Set (O,"length" ,+0 _{𝔽},true ).  Return
undefined .
 Perform ?
 Else,
The pop
function is intentionally generic; it does not require that its
23.1.3.20 Array.prototype.push ( ...items )
The arguments are appended to the end of the array, in the order in which they appear. The new length of the array is returned as the result of the call.
When the push
method is called with zero or more arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  Let argCount be the number of elements in items.
 If len + argCount > 2^{53}  1, throw a
TypeError exception.  For each element E of items, do
 Perform ?
Set (O,"length" ,𝔽 (len),true ).  Return
𝔽 (len).
The push
method is
The push
function is intentionally generic; it does not require that its
23.1.3.21 Array.prototype.reduce ( callbackfn [ , initialValue ] )
callbackfn should be a function that takes four arguments. reduce
calls the callback, as a function, once for each element after the first element present in the array, in ascending order.
callbackfn is called with four arguments: the previousValue (value from the previous call to callbackfn), the currentValue (value of the current element), the currentIndex, and the object being traversed. The first time that callback is called, the previousValue and currentValue can be one of two values. If an initialValue was supplied in the call to reduce
, then previousValue will be equal to initialValue and currentValue will be equal to the first value in the array. If no initialValue was supplied, then previousValue will be equal to the first value in the array and currentValue will be equal to the second. It is a
reduce
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.
The range of elements processed by reduce
is set before the first call to callbackfn. Elements that are appended to the array after the call to reduce
begins will not be visited by callbackfn. If existing elements of the array are changed, their value as passed to callbackfn will be the value at the time reduce
visits them; elements that are deleted after the call to reduce
begins and before being visited are not visited.
When the reduce
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (callbackfn) isfalse , throw aTypeError exception.  If len = 0 and initialValue is not present, throw a
TypeError exception.  Let k be 0.
 Let accumulator be
undefined .  If initialValue is present, then
 Set accumulator to initialValue.
 Else,
 Let kPresent be
false .  Repeat, while kPresent is
false and k < len, Let Pk be !
ToString (𝔽 (k)).  Set kPresent to ?
HasProperty (O, Pk).  If kPresent is
true , then Set accumulator to ?
Get (O, Pk).
 Set accumulator to ?
 Set k to k + 1.
 Let Pk be !
 If kPresent is
false , throw aTypeError exception.
 Let kPresent be
 Repeat, while k < len,
 Return accumulator.
The reduce
function is intentionally generic; it does not require that its
23.1.3.22 Array.prototype.reduceRight ( callbackfn [ , initialValue ] )
callbackfn should be a function that takes four arguments. reduceRight
calls the callback, as a function, once for each element after the first element present in the array, in descending order.
callbackfn is called with four arguments: the previousValue (value from the previous call to callbackfn), the currentValue (value of the current element), the currentIndex, and the object being traversed. The first time the function is called, the previousValue and currentValue can be one of two values. If an initialValue was supplied in the call to reduceRight
, then previousValue will be equal to initialValue and currentValue will be equal to the last value in the array. If no initialValue was supplied, then previousValue will be equal to the last value in the array and currentValue will be equal to the secondtolast value. It is a
reduceRight
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.
The range of elements processed by reduceRight
is set before the first call to callbackfn. Elements that are appended to the array after the call to reduceRight
begins will not be visited by callbackfn. If existing elements of the array are changed by callbackfn, their value as passed to callbackfn will be the value at the time reduceRight
visits them; elements that are deleted after the call to reduceRight
begins and before being visited are not visited.
When the reduceRight
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (callbackfn) isfalse , throw aTypeError exception.  If len is 0 and initialValue is not present, throw a
TypeError exception.  Let k be len  1.
 Let accumulator be
undefined .  If initialValue is present, then
 Set accumulator to initialValue.
 Else,
 Let kPresent be
false .  Repeat, while kPresent is
false and k ≥ 0, Let Pk be !
ToString (𝔽 (k)).  Set kPresent to ?
HasProperty (O, Pk).  If kPresent is
true , then Set accumulator to ?
Get (O, Pk).
 Set accumulator to ?
 Set k to k  1.
 Let Pk be !
 If kPresent is
false , throw aTypeError exception.
 Let kPresent be
 Repeat, while k ≥ 0,
 Return accumulator.
The reduceRight
function is intentionally generic; it does not require that its
23.1.3.23 Array.prototype.reverse ( )
The elements of the array are rearranged so as to reverse their order. The object is returned as the result of the call.
When the reverse
method is called, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  Let middle be
floor (len / 2).  Let lower be 0.
 Repeat, while lower ≠ middle,
 Let upper be len  lower  1.
 Let upperP be !
ToString (𝔽 (upper)).  Let lowerP be !
ToString (𝔽 (lower)).  Let lowerExists be ?
HasProperty (O, lowerP).  If lowerExists is
true , then Let lowerValue be ?
Get (O, lowerP).
 Let lowerValue be ?
 Let upperExists be ?
HasProperty (O, upperP).  If upperExists is
true , then Let upperValue be ?
Get (O, upperP).
 Let upperValue be ?
 If lowerExists is
true and upperExists istrue , then  Else if lowerExists is
false and upperExists istrue , then Perform ?
Set (O, lowerP, upperValue,true ).  Perform ?
DeletePropertyOrThrow (O, upperP).
 Perform ?
 Else if lowerExists is
true and upperExists isfalse , then Perform ?
DeletePropertyOrThrow (O, lowerP).  Perform ?
Set (O, upperP, lowerValue,true ).
 Perform ?
 Else,
Assert : lowerExists and upperExists are bothfalse . No action is required.
 Set lower to lower + 1.
 Return O.
The reverse
function is intentionally generic; it does not require that its
23.1.3.24 Array.prototype.shift ( )
The first element of the array is removed from the array and returned.
When the shift
method is called, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If len = 0, then
 Perform ?
Set (O,"length" ,+0 _{𝔽},true ).  Return
undefined .
 Perform ?
 Let first be ?
Get (O,"0" ).  Let k be 1.
 Repeat, while k < len,
 Let from be !
ToString (𝔽 (k)).  Let to be !
ToString (𝔽 (k  1)).  Let fromPresent be ?
HasProperty (O, from).  If fromPresent is
true , then  Else,
Assert : fromPresent isfalse . Perform ?
DeletePropertyOrThrow (O, to).
 Set k to k + 1.
 Let from be !
 Perform ?
DeletePropertyOrThrow (O, !ToString (𝔽 (len  1))).  Perform ?
Set (O,"length" ,𝔽 (len  1),true ).  Return first.
The shift
function is intentionally generic; it does not require that its
23.1.3.25 Array.prototype.slice ( start, end )
The slice
method takes two arguments, start and end, and returns an array containing the elements of the array from element start up to, but not including, element end (or through the end of the array if end is
The following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  Let relativeStart be ?
ToIntegerOrInfinity (start).  If relativeStart is ∞, let k be 0.
 Else if relativeStart < 0, let k be
max (len + relativeStart, 0).  Else, let k be
min (relativeStart, len).  If end is
undefined , let relativeEnd be len; else let relativeEnd be ?ToIntegerOrInfinity (end).  If relativeEnd is ∞, let final be 0.
 Else if relativeEnd < 0, let final be
max (len + relativeEnd, 0).  Else, let final be
min (relativeEnd, len).  Let count be
max (final  k, 0).  Let A be ?
ArraySpeciesCreate (O, count).  Let n be 0.
 Repeat, while k < final,
 Let Pk be !
ToString (𝔽 (k)).  Let kPresent be ?
HasProperty (O, Pk).  If kPresent is
true , then Let kValue be ?
Get (O, Pk).  Perform ?
CreateDataPropertyOrThrow (A, !ToString (𝔽 (n)), kValue).
 Let kValue be ?
 Set k to k + 1.
 Set n to n + 1.
 Let Pk be !
 Perform ?
Set (A,"length" ,𝔽 (n),true ).  Return A.
The explicit setting of the
The slice
function is intentionally generic; it does not require that its
23.1.3.26 Array.prototype.some ( callbackfn [ , thisArg ] )
callbackfn should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. some
calls callbackfn once for each element present in the array, in ascending order, until it finds one where callbackfn returns some
immediately returns some
returns
If a thisArg parameter is provided, it will be used as the
callbackfn is called with three arguments: the value of the element, the index of the element, and the object being traversed.
some
does not directly mutate the object on which it is called but the object may be mutated by the calls to callbackfn.
The range of elements processed by some
is set before the first call to callbackfn. Elements that are appended to the array after the call to some
begins will not be visited by callbackfn. If existing elements of the array are changed, their value as passed to callbackfn will be the value at the time that some
visits them; elements that are deleted after the call to some
begins and before being visited are not visited. some
acts like the "exists" quantifier in mathematics. In particular, for an empty array, it returns
When the some
method is called with one or two arguments, the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  If
IsCallable (callbackfn) isfalse , throw aTypeError exception.  Let k be 0.
 Repeat, while k < len,
 Return
false .
The some
function is intentionally generic; it does not require that its
23.1.3.27 Array.prototype.sort ( comparefn )
The elements of this array are sorted. The sort must be stable (that is, elements that compare equal must remain in their original order). If comparefn is not
The following steps are taken:
 If comparefn is not
undefined andIsCallable (comparefn) isfalse , throw aTypeError exception.  Let obj be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (obj).  Let items be a new empty
List .  Let k be 0.
 Repeat, while k < len,
 Let Pk be !
ToString (𝔽 (k)).  Let kPresent be ?
HasProperty (obj, Pk).  If kPresent is
true , then Let kValue be ?
Get (obj, Pk).  Append kValue to items.
 Let kValue be ?
 Set k to k + 1.
 Let Pk be !
 Let itemCount be the number of elements in items.
 Sort items using an
implementationdefined sequence of calls toSortCompare . If any such call returns anabrupt completion , stop before performing any further calls toSortCompare or steps in this algorithm and return that completion.  Let j be 0.
 Repeat, while j < itemCount,
 Repeat, while j < len,
 Perform ?
DeletePropertyOrThrow (obj, !ToString (𝔽 (j))).  Set j to j + 1.
 Perform ?
 Return obj.
The sort order is the ordering, after completion of this function, of the sort
function is then determined as follows:
The sort order is

If comparefn is not
undefined and is not a consistent comparison function for the elements of items (see below). 
If comparefn is
undefined andSortCompare does not act as a consistent comparison function. 
If comparefn is
undefined and all applications ofToString , to any specific value passed as an argument toSortCompare , do not produce the same result.
Unless the sort order is specified above to be

There must be some mathematical permutation π of the nonnegative integers less than itemCount, such that for every nonnegative
integer j less than itemCount, the elementold[j] is exactly the same asnew[π(j)] . 
Then for all nonnegative integers j and k, each less than itemCount, if
(seeSortCompare (old[j], old[k]) < 0SortCompare below), thenπ(j) < π(k) .
Here the notation
A function comparefn is a consistent comparison function for a set of values S if all of the requirements below are met for all values a, b, and c (possibly the same value) in the set S: The notation

Calling comparefn(a, b) always returns the same value v when given a specific pair of values a and b as its two arguments. Furthermore,
Type (v) is Number, and v is notNaN . Note that this implies that exactly one of a <_{CF} b, a =_{CF} b, and a >_{CF} b will be true for a given pair of a and b.  Calling comparefn(a, b) does not modify obj or any object on obj's prototype chain.
 a =_{CF} a (reflexivity)
 If a =_{CF} b, then b =_{CF} a (symmetry)
 If a =_{CF} b and b =_{CF} c, then a =_{CF} c (transitivity of =_{CF})
 If a <_{CF} b and b <_{CF} c, then a <_{CF} c (transitivity of <_{CF})
 If a >_{CF} b and b >_{CF} c, then a >_{CF} c (transitivity of >_{CF})
The above conditions are necessary and sufficient to ensure that comparefn divides the set S into equivalence classes and that these equivalence classes are totally ordered.
The sort
function is intentionally generic; it does not require that its
23.1.3.27.1 SortCompare ( x, y )
The abstract operation SortCompare takes arguments x and y. It also has access to the comparefn argument passed to the current invocation of the sort
method. It performs the following steps when called:
 If x and y are both
undefined , return+0 _{𝔽}.  If x is
undefined , return1 _{𝔽}.  If y is
undefined , return1 _{𝔽}.  If comparefn is not
undefined , then  Let xString be ?
ToString (x).  Let yString be ?
ToString (y).  Let xSmaller be the result of performing
Abstract Relational Comparison xString < yString.  If xSmaller is
true , return1 _{𝔽}.  Let ySmaller be the result of performing
Abstract Relational Comparison yString < xString.  If ySmaller is
true , return1 _{𝔽}.  Return
+0 _{𝔽}.
Because nonexistent property values always compare greater than
Method calls performed by the
23.1.3.28 Array.prototype.splice ( start, deleteCount, ...items )
When the splice
method is called with two or more arguments start, deleteCount and zero or more items, the deleteCount elements of the array starting at
The following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  Let relativeStart be ?
ToIntegerOrInfinity (start).  If relativeStart is ∞, let actualStart be 0.
 Else if relativeStart < 0, let actualStart be
max (len + relativeStart, 0).  Else, let actualStart be
min (relativeStart, len).  If start is not present, then
 Let insertCount be 0.
 Let actualDeleteCount be 0.
 Else if deleteCount is not present, then
 Let insertCount be 0.
 Let actualDeleteCount be len  actualStart.
 Else,
 Let insertCount be the number of elements in items.
 Let dc be ?
ToIntegerOrInfinity (deleteCount).  Let actualDeleteCount be the result of
clamping dc between 0 and len  actualStart.
 If len + insertCount  actualDeleteCount > 2^{53}  1, throw a
TypeError exception.  Let A be ?
ArraySpeciesCreate (O, actualDeleteCount).  Let k be 0.
 Repeat, while k < actualDeleteCount,
 Let from be !
ToString (𝔽 (actualStart + k)).  Let fromPresent be ?
HasProperty (O, from).  If fromPresent is
true , then Let fromValue be ?
Get (O, from).  Perform ?
CreateDataPropertyOrThrow (A, !ToString (𝔽 (k)), fromValue).
 Let fromValue be ?
 Set k to k + 1.
 Let from be !
 Perform ?
Set (A,"length" ,𝔽 (actualDeleteCount),true ).  Let itemCount be the number of elements in items.
 If itemCount < actualDeleteCount, then
 Set k to actualStart.
 Repeat, while k < (len  actualDeleteCount),
 Let from be !
ToString (𝔽 (k + actualDeleteCount)).  Let to be !
ToString (𝔽 (k + itemCount)).  Let fromPresent be ?
HasProperty (O, from).  If fromPresent is
true , then  Else,
Assert : fromPresent isfalse . Perform ?
DeletePropertyOrThrow (O, to).
 Set k to k + 1.
 Let from be !
 Set k to len.
 Repeat, while k > (len  actualDeleteCount + itemCount),
 Perform ?
DeletePropertyOrThrow (O, !ToString (𝔽 (k  1))).  Set k to k  1.
 Perform ?
 Else if itemCount > actualDeleteCount, then
 Set k to (len  actualDeleteCount).
 Repeat, while k > actualStart,
 Let from be !
ToString (𝔽 (k + actualDeleteCount  1)).  Let to be !
ToString (𝔽 (k + itemCount  1)).  Let fromPresent be ?
HasProperty (O, from).  If fromPresent is
true , then  Else,
Assert : fromPresent isfalse . Perform ?
DeletePropertyOrThrow (O, to).
 Set k to k  1.
 Let from be !
 Set k to actualStart.
 For each element E of items, do
 Perform ?
Set (O,"length" ,𝔽 (len  actualDeleteCount + itemCount),true ).  Return A.
The explicit setting of the
The splice
function is intentionally generic; it does not require that its
23.1.3.29 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
An ECMAScript implementation that includes the ECMA402 Internationalization API must implement the Array.prototype.toLocaleString
method as specified in the ECMA402 specification. If an ECMAScript implementation does not include the ECMA402 API the following specification of the toLocaleString
method is used.
The first edition of ECMA402 did not include a replacement specification for the Array.prototype.toLocaleString
method.
The meanings of the optional parameters to this method are defined in the ECMA402 specification; implementations that do not include ECMA402 support must not use those parameter positions for anything else.
The following steps are taken:
 Let array be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (array).  Let separator be the String value for the listseparator String appropriate for the
host environment 's current locale (this is derived in animplementationdefined way).  Let R be the empty String.
 Let k be 0.
 Repeat, while k < len,
 If k > 0, then
 Set R to the
stringconcatenation of R and separator.
 Set R to the
 Let nextElement be ?
Get (array, !ToString (𝔽 (k))).  If nextElement is not
undefined ornull , then Let S be ?
ToString (?Invoke (nextElement,"toLocaleString" )).  Set R to the
stringconcatenation of R and S.
 Let S be ?
 Set k to k + 1.
 If k > 0, then
 Return R.
The elements of the array are converted to Strings using their toLocaleString
methods, and these Strings are then concatenated, separated by occurrences of a separator String that has been derived in an toString
, except that the result of this function is intended to be localespecific.
The toLocaleString
function is intentionally generic; it does not require that its
23.1.3.30 Array.prototype.toString ( )
When the toString
method is called, the following steps are taken:
 Let array be ?
ToObject (this value).  Let func be ?
Get (array,"join" ).  If
IsCallable (func) isfalse , set func to the intrinsic function %Object.prototype.toString%.  Return ?
Call (func, array).
The toString
function is intentionally generic; it does not require that its
23.1.3.31 Array.prototype.unshift ( ...items )
The arguments are prepended to the start of the array, such that their order within the array is the same as the order in which they appear in the argument list.
When the unshift
method is called with zero or more arguments item1, item2, etc., the following steps are taken:
 Let O be ?
ToObject (this value).  Let len be ?
LengthOfArrayLike (O).  Let argCount be the number of elements in items.
 If argCount > 0, then
 If len + argCount > 2^{53}  1, throw a
TypeError exception.  Let k be len.
 Repeat, while k > 0,
 Let from be !
ToString (𝔽 (k  1)).  Let to be !
ToString (𝔽 (k + argCount  1)).  Let fromPresent be ?
HasProperty (O, from).  If fromPresent is
true , then  Else,
Assert : fromPresent isfalse . Perform ?
DeletePropertyOrThrow (O, to).
 Set k to k  1.
 Let from be !
 Let j be
+0 _{𝔽}.  For each element E of items, do
 If len + argCount > 2^{53}  1, throw a
 Perform ?
Set (O,"length" ,𝔽 (len + argCount),true ).  Return
𝔽 (len + argCount).
The unshift
method is
The unshift
function is intentionally generic; it does not require that its
23.1.3.32 Array.prototype.values ( )
The following steps are taken:
 Let O be ?
ToObject (this value).  Return
CreateArrayIterator (O,value ).
23.1.3.33 Array.prototype [ @@iterator ] ( )
The initial value of the Array.prototype.values
property.
23.1.3.34 Array.prototype [ @@unscopables ]
The initial value of the
 Let unscopableList be !
OrdinaryObjectCreate (null ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"copyWithin" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"entries" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"fill" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"find" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"findIndex" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"flat" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"flatMap" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"includes" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"keys" ,true ).  Perform !
CreateDataPropertyOrThrow (unscopableList,"values" ,true ).  Return unscopableList.
This property has the attributes { [[Writable]]:
The own property names of this object are property names that were not included as standard properties of Array.prototype
prior to the ECMAScript 2015 specification. These names are ignored for with
statement binding purposes in order to preserve the behaviour of existing code that might use one of these names as a binding in an outer scope that is shadowed by a with
statement whose binding object is an Array object.
23.1.4 Properties of Array Instances
Array instances are Array exotic objects and have the internal methods specified for such objects. Array instances inherit properties from the
Array instances have a
23.1.4.1 length
The
The
Reducing the value of the
23.1.5 Array Iterator Objects
An Array Iterator is an object, that represents a specific iteration over some specific Array instance object. There is not a named
23.1.5.1 CreateArrayIterator ( array, kind )
The abstract operation CreateArrayIterator takes arguments array and kind. This operation is used to create iterator objects for Array methods that return such iterators. It performs the following steps when called:
Assert :Type (array) is Object.Assert : kind iskey+value ,key , orvalue . Let closure be a new
Abstract Closure with no parameters that captures kind and array and performs the following steps when called: Let index be 0.
 Repeat,
 If array has a [[TypedArrayName]] internal slot, then
 If
IsDetachedBuffer (array.[[ViewedArrayBuffer]]) istrue , throw aTypeError exception.  Let len be array.[[ArrayLength]].
 If
 Else,
 Let len be ?
LengthOfArrayLike (array).
 Let len be ?
 If index ≥ len, return
undefined .  If kind is
key , perform ?Yield (𝔽 (index)).  Else,
 Set index to index + 1.
 If array has a [[TypedArrayName]] internal slot, then
 Return !
CreateIteratorFromClosure (closure,"%ArrayIteratorPrototype%" ,%ArrayIteratorPrototype% ).
23.1.5.2 The %ArrayIteratorPrototype% Object
The %ArrayIteratorPrototype% object:
 has properties that are inherited by all Array Iterator Objects.
 is an
ordinary object .  has a [[Prototype]] internal slot whose value is
%IteratorPrototype% .  has the following properties:
23.1.5.2.1 %ArrayIteratorPrototype%.next ( )
 Return ?
GeneratorResume (this value,empty ,"%ArrayIteratorPrototype%" ).
23.1.5.2.2 %ArrayIteratorPrototype% [ @@toStringTag ]
The initial value of the
This property has the attributes { [[Writable]]: