23.1 Array Objects
Arrays are
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 when called as a
constructor . - also creates and initializes a new Array 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.
- may be used as the value of an
extends
clause of a class definition. Subclassconstructors that intend to inherit the exotic Array behaviour must include asuper
call to the Arrayconstructor to initialize subclass instances that areArray exotic objects . However, most of theArray.prototype
methods are generic methods that are not dependent upon theirthis value being anArray exotic object .
23.1.1.1 Array ( ...values )
This function performs the following steps when called:
- 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 len
is not a Number , then- Perform !
CreateDataPropertyOrThrow (array,"0" , len). - Let intLen be
1 𝔽.
- Perform !
- Else,
- Let intLen be !
ToUint32 (len). - If
SameValueZero (intLen, len) isfalse , throw aRangeError 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 a
"length" property whose value is1 𝔽. - has the following properties:
23.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
This method performs the following steps when called:
- Let C be the
this value. - If mapfn is
undefined , then- Let mapping be
false .
- Let mapping be
- 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 ?
GetIteratorFromMethod (items, usingIterator). - Let k be 0.
- Repeat,
- If k ≥ 253 - 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 ?
IteratorStepValue (iteratorRecord). - If next is
done , then - If mapping is
true , then- Let mappedValue be
Completion (Call (mapfn, thisArg, « next,𝔽 (k) »)). IfAbruptCloseIterator (mappedValue, iteratorRecord).
- Let mappedValue be
- Else,
- Let mappedValue be next.
- Let defineStatus be
Completion (CreateDataPropertyOrThrow (A, Pk, mappedValue)). IfAbruptCloseIterator (defineStatus, iteratorRecord).- Set k to k + 1.
- If k ≥ 253 - 1, then
- If
- NOTE: items is not an Iterable so assume it is an
array-like 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.
This method is an intentionally generic factory method; it does not require that its
23.1.2.2 Array.isArray ( arg )
This function performs the following steps when called:
- Return ?
IsArray (arg).
23.1.2.3 Array.of ( ...items )
This method performs the following steps when called:
- 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.
This method 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.at ( index )
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let relativeIndex be ?
ToIntegerOrInfinity (index). - If relativeIndex ≥ 0, then
- Let k be relativeIndex.
- Else,
- Let k be len + relativeIndex.
- If k < 0 or k ≥ len, return
undefined . - Return ?
Get (O, !ToString (𝔽 (k))).
23.1.3.2 Array.prototype.concat ( ...items )
This method returns an array containing the array elements of the object followed by the array elements of each argument.
It performs the following steps when called:
- 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 len be ?
LengthOfArrayLike (E). - If n + len > 253 - 1, throw a
TypeError exception. - Let k be 0.
- Repeat, while k < len,
- Let Pk be !
ToString (𝔽 (k)). - Let exists be ?
HasProperty (E, Pk). - If exists is
true , then- Let subElement be ?
Get (E, Pk). - Perform ?
CreateDataPropertyOrThrow (A, !ToString (𝔽 (n)), subElement).
- Let subElement be ?
- Set n to n + 1.
- Set k to k + 1.
- Let Pk be !
- Let len be ?
- Else,
- NOTE: E is added as a single item rather than spread.
- If n ≥ 253 - 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
The explicit setting of the
This method is intentionally generic; it does not require that its
23.1.3.2.1 IsConcatSpreadable ( O )
The abstract operation IsConcatSpreadable takes argument O (an
- If O
is not an Object , returnfalse . - Let spreadable be ?
Get (O,@@isConcatSpreadable ). - If spreadable is not
undefined , returnToBoolean (spreadable). - Return ?
IsArray (O).
23.1.3.3 Array.prototype.constructor
The initial value of Array.prototype.constructor
is
23.1.3.4 Array.prototype.copyWithin ( target, start [ , end ] )
The end argument is optional. If it is not provided, the length of the
If target is negative, it is treated as
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let relativeTarget be ?
ToIntegerOrInfinity (target). - If relativeTarget = -∞, 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 = -∞, 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 = -∞, 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.
This method is intentionally generic; it does not require that its
23.1.3.5 Array.prototype.entries ( )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Return
CreateArrayIterator (O,key+value ).
23.1.3.6 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
This method performs the following steps when called:
- 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 .
This method is intentionally generic; it does not require that its
23.1.3.7 Array.prototype.fill ( value [ , start [ , end ] ] )
The start argument is optional. If it is not provided,
The end argument is optional. If it is not provided, the length of the
If start is negative, it is treated as
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, 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 = -∞, 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.
This method is intentionally generic; it does not require that its
23.1.3.8 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.
This method performs the following steps when called:
- 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.
This method is intentionally generic; it does not require that its
23.1.3.9 Array.prototype.find ( predicate [ , thisArg ] )
This method calls predicate once for each element of the array, in ascending index order, until it finds one where predicate returns a value that coerces to find
immediately returns that element value. Otherwise, find
returns
See
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let findRec be ?
FindViaPredicate (O, len,ascending , predicate, thisArg). - Return findRec.[[Value]].
This method is intentionally generic; it does not require that its
23.1.3.10 Array.prototype.findIndex ( predicate [ , thisArg ] )
This method calls predicate once for each element of the array, in ascending index order, until it finds one where predicate returns a value that coerces to findIndex
immediately returns the index of that element value. Otherwise, findIndex
returns -1.
See
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let findRec be ?
FindViaPredicate (O, len,ascending , predicate, thisArg). - Return findRec.[[Index]].
This method is intentionally generic; it does not require that its
23.1.3.11 Array.prototype.findLast ( predicate [ , thisArg ] )
This method calls predicate once for each element of the array, in descending index order, until it finds one where predicate returns a value that coerces to findLast
immediately returns that element value. Otherwise, findLast
returns
See
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let findRec be ?
FindViaPredicate (O, len,descending , predicate, thisArg). - Return findRec.[[Value]].
This method is intentionally generic; it does not require that its
23.1.3.12 Array.prototype.findLastIndex ( predicate [ , thisArg ] )
This method calls predicate once for each element of the array, in descending index order, until it finds one where predicate returns a value that coerces to findLastIndex
immediately returns the index of that element value. Otherwise, findLastIndex
returns -1.
See
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let findRec be ?
FindViaPredicate (O, len,descending , predicate, thisArg). - Return findRec.[[Index]].
This method is intentionally generic; it does not require that its
23.1.3.12.1 FindViaPredicate ( O, len, direction, predicate, thisArg )
The abstract operation FindViaPredicate takes arguments O (an Object), len (a non-negative
O should be an
predicate should be a function. When called for an element of the array, it is passed three arguments: the value of the element, the index of the element, and the object being traversed. Its return value will be coerced to a Boolean value.
thisArg will be used as the
This operation 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 is set before the first call to predicate, just before the traversal begins. Elements that are appended to the array after this 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 this operation visits them. Elements that are deleted after traversal begins and before being visited are still visited and are either looked up from the prototype or are
It performs the following steps when called:
- If
IsCallable (predicate) isfalse , throw aTypeError exception. - If direction is
ascending , then - Else,
- For each
integer k of indices, do- Let Pk be !
ToString (𝔽 (k)). - NOTE: If O is a
TypedArray , the following invocation ofGet will return anormal completion . - Let kValue be ?
Get (O, Pk). - Let testResult be ?
Call (predicate, thisArg, « kValue,𝔽 (k), O »). - If
ToBoolean (testResult) istrue , return theRecord { [[Index]]:𝔽 (k), [[Value]]: kValue }.
- Let Pk be !
- Return the
Record { [[Index]]:-1 𝔽, [[Value]]:undefined }.
23.1.3.13 Array.prototype.flat ( [ depth ] )
This method performs the following steps when called:
- 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.13.1 FlattenIntoArray ( target, source, sourceLen, start, depth [ , mapperFunction [ , thisArg ] ] )
The abstract operation FlattenIntoArray takes arguments target (an Object), source (an Object), sourceLen (a non-negative
Assert : If mapperFunction is present, thenIsCallable (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 = +∞, 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 ≥ 253 - 1, throw a
TypeError exception. - Perform ?
CreateDataPropertyOrThrow (target, !ToString (𝔽 (targetIndex)), element). - Set targetIndex to targetIndex + 1.
- If targetIndex ≥ 253 - 1, throw a
- Let element be ?
- Set sourceIndex to sourceIndex +
1 𝔽.
- Let P be !
- Return targetIndex.
23.1.3.14 Array.prototype.flatMap ( mapperFunction [ , thisArg ] )
This method performs the following steps when called:
- 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.15 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.
This method performs the following steps when called:
- 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 .
This method is intentionally generic; it does not require that its
23.1.3.16 Array.prototype.includes ( searchElement [ , fromIndex ] )
This method compares searchElement to the elements of the array, in ascending order, using the
The optional second argument fromIndex defaults to
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - If len = 0, return
false . - Let n be ?
ToIntegerOrInfinity (fromIndex). Assert : If fromIndex isundefined , then n is 0.- If n = +∞, return
false . - Else if n = -∞, 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 .
This method is intentionally generic; it does not require that its
This method intentionally differs from the similar indexOf
method in two ways. First, it uses the
23.1.3.17 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
This method compares searchElement to the elements of the array, in ascending order, using the
The optional second argument fromIndex defaults to
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - If len = 0, return
-1 𝔽. - Let n be ?
ToIntegerOrInfinity (fromIndex). Assert : If fromIndex isundefined , then n is 0.- If n = +∞, return
-1 𝔽. - Else if n = -∞, 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))). - If
IsStrictlyEqual (searchElement, elementK) istrue , return𝔽 (k).
- Let elementK be ?
- Set k to k + 1.
- Let kPresent be ?
- Return
-1 𝔽.
This method is intentionally generic; it does not require that its
23.1.3.18 Array.prototype.join ( separator )
This method converts the elements of the array to Strings, and then concatenates these Strings, separated by occurrences of the separator. If no separator is provided, a single comma is used as the separator.
It performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - If separator is
undefined , let sep be"," . - 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
string-concatenation of R and sep. - Let element be ?
Get (O, !ToString (𝔽 (k))). - If element is either
undefined ornull , let next be the empty String; otherwise, let next be ?ToString (element). - Set R to the
string-concatenation of R and next. - Set k to k + 1.
- If k > 0, set R to the
- Return R.
This method is intentionally generic; it does not require that its
23.1.3.19 Array.prototype.keys ( )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Return
CreateArrayIterator (O,key ).
23.1.3.20 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
This method 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
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - If len = 0, return
-1 𝔽. - If fromIndex is present, let n be ?
ToIntegerOrInfinity (fromIndex); else let n be len - 1. - If n = -∞, 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))). - If
IsStrictlyEqual (searchElement, elementK) istrue , return𝔽 (k).
- Let elementK be ?
- Set k to k - 1.
- Let kPresent be ?
- Return
-1 𝔽.
This method is intentionally generic; it does not require that its
23.1.3.21 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.
This method performs the following steps when called:
- 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.
This method is intentionally generic; it does not require that its
23.1.3.22 Array.prototype.pop ( )
This method removes the last element of the array and returns it.
This method performs the following steps when called:
- 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,
This method is intentionally generic; it does not require that its
23.1.3.23 Array.prototype.push ( ...items )
This method appends the arguments to the end of the array, in the order in which they appear. It returns the new length of the array.
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let argCount be the number of elements in items.
- If len + argCount > 253 - 1, throw a
TypeError exception. - For each element E of items, do
- Perform ?
Set (O,"length" ,𝔽 (len),true ). - Return
𝔽 (len).
The
This method is intentionally generic; it does not require that its
23.1.3.24 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 initialValue and currentValue will be the first value in the array. If no initialValue was supplied, then previousValue will be the first value in the array and currentValue will be 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.
This method performs the following steps when called:
- 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.
This method is intentionally generic; it does not require that its
23.1.3.25 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 initialValue and currentValue will be the last value in the array. If no initialValue was supplied, then previousValue will be the last value in the array and currentValue will be the second-to-last 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.
This method performs the following steps when called:
- 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 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.
This method is intentionally generic; it does not require that its
23.1.3.26 Array.prototype.reverse ( )
This method rearranges the elements of the array so as to reverse their order. It returns the object as the result of the call.
This method performs the following steps when called:
- 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 .- NOTE: No action is required.
- Set lower to lower + 1.
- Return O.
This method is intentionally generic; it does not require that its
23.1.3.27 Array.prototype.shift ( )
This method removes the first element of the array and returns it.
It performs the following steps when called:
- 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.
This method is intentionally generic; it does not require that its
23.1.3.28 Array.prototype.slice ( start, end )
This method 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
It performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, 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 = -∞, 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
This method is intentionally generic; it does not require that its
23.1.3.29 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
This method performs the following steps when called:
- 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 .
This method is intentionally generic; it does not require that its
23.1.3.30 Array.prototype.sort ( comparefn )
This method sorts the elements of this array. The sort must be stable (that is, elements that compare equal must remain in their original order). If comparefn is not
It performs the following steps when called:
- If comparefn is not
undefined andIsCallable (comparefn) isfalse , throw aTypeError exception. - Let obj be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (obj). - Let SortCompare be a new
Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called:- Return ?
CompareArrayElements (x, y, comparefn).
- Return ?
- Let sortedList be ?
SortIndexedProperties (obj, len, SortCompare,skip-holes ). - Let itemCount be the number of elements in sortedList.
- Let j be 0.
- Repeat, while j < itemCount,
- NOTE: The call to
SortIndexedProperties in step5 usesskip-holes . The remaining indices are deleted to preserve the number of holes that were detected and excluded from the sort. - Repeat, while j < len,
- Perform ?
DeletePropertyOrThrow (obj, !ToString (𝔽 (j))). - Set j to j + 1.
- Perform ?
- Return obj.
Because non-existent property values always compare greater than
Method calls performed by the
This method is intentionally generic; it does not require that its
23.1.3.30.1 SortIndexedProperties ( obj, len, SortCompare, holes )
The abstract operation SortIndexedProperties takes arguments obj (an Object), len (a non-negative
- Let items be a new empty
List . - Let k be 0.
- Repeat, while k < len,
- Let Pk be !
ToString (𝔽 (k)). - If holes is
skip-holes , then- Let kRead be ?
HasProperty (obj, Pk).
- Let kRead be ?
- Else,
Assert : holes isread-through-holes .- Let kRead be
true .
- If kRead is
true , then- Let kValue be ?
Get (obj, Pk). - Append kValue to items.
- Let kValue be ?
- Set k to k + 1.
- Let Pk be !
- Sort items using an
implementation-defined sequence of calls to SortCompare. If any such call returns anabrupt completion , stop before performing any further calls to SortCompare and return thatCompletion Record . - Return items.
The sort order is the ordering of items after completion of step
Unless the
-
There must be some mathematical permutation π of the non-negative
integers less than itemCount, such that for every non-negativeinteger j less than itemCount, the elementold[j] is exactly the same asnew[π(j)] . -
Then for all non-negative
integers j and k, each less than itemCount, if , thenℝ (SortCompare(old[j], old[k])) < 0π(j) < π(k) .
Here the notation
An abstract closure or function comparator is a consistent comparator 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 comparator(a, b) always returns the same value v when given a specific pair of values a and b as its two arguments. Furthermore, v
is a Number , and v is notNaN . Note that this implies that exactly one of a <C b, a =C b, and a >C b will be true for a given pair of a and b. - Calling comparator(a, b) does not modify obj or any object on obj's prototype chain.
- a =C a (reflexivity)
- If a =C b, then b =C a (symmetry)
- If a =C b and b =C c, then a =C c (transitivity of =C)
- If a <C b and b <C c, then a <C c (transitivity of <C)
- If a >C b and b >C c, then a >C c (transitivity of >C)
The above conditions are necessary and sufficient to ensure that comparator divides the set S into equivalence classes and that these equivalence classes are totally ordered.
23.1.3.30.2 CompareArrayElements ( x, y, comparefn )
The abstract operation CompareArrayElements takes arguments x (an
- If x and y are both
undefined , return+0 𝔽. - If x is
undefined , return1 𝔽. - If y is
undefined , return-1 𝔽. - If comparefn is not
undefined , then - Let xString be ?
ToString (x). - Let yString be ?
ToString (y). - Let xSmaller be !
IsLessThan (xString, yString,true ). - If xSmaller is
true , return-1 𝔽. - Let ySmaller be !
IsLessThan (yString, xString,true ). - If ySmaller is
true , return1 𝔽. - Return
+0 𝔽.
23.1.3.31 Array.prototype.splice ( start, deleteCount, ...items )
This method deletes the deleteCount elements of the array starting at
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let actualStart be 0.
- Else if relativeStart < 0, let actualStart be
max (len + relativeStart, 0). - Else, let actualStart be
min (relativeStart, len). - Let itemCount be the number of elements in items.
- If start is not present, then
- Let actualDeleteCount be 0.
- Else if deleteCount is not present, then
- Let actualDeleteCount be len - actualStart.
- Else,
- Let dc be ?
ToIntegerOrInfinity (deleteCount). - Let actualDeleteCount be the result of
clamping dc between 0 and len - actualStart.
- Let dc be ?
- If len + itemCount - actualDeleteCount > 253 - 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)). - If ?
HasProperty (O, from) istrue , 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 ). - 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)). - If ?
HasProperty (O, from) istrue , then - Else,
- Perform ?
DeletePropertyOrThrow (O, to).
- Perform ?
- 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)). - If ?
HasProperty (O, from) istrue , then - Else,
- Perform ?
DeletePropertyOrThrow (O, to).
- Perform ?
- 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.
This method is intentionally generic; it does not require that its
23.1.3.32 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.
The first edition of ECMA-402 did not include a replacement specification for this method.
The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.
This method performs the following steps when called:
- Let array be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (array). - Let separator be the
implementation-defined list-separator String value appropriate for thehost environment 's current locale (such as", " ). - Let R be the empty String.
- Let k be 0.
- Repeat, while k < len,
- If k > 0, then
- Set R to the
string-concatenation of R and separator.
- Set R to the
- Let nextElement be ?
Get (array, !ToString (𝔽 (k))). - If nextElement is neither
undefined nornull , then- Let S be ?
ToString (?Invoke (nextElement,"toLocaleString" )). - Set R to the
string-concatenation of R and S.
- Let S be ?
- Set k to k + 1.
- If k > 0, then
- Return R.
This method converts the elements of the array to Strings using their toLocaleString
methods, and then concatenates these Strings, separated by occurrences of an toString
except that it is intended to yield a locale-sensitive result corresponding with conventions of the
This method is intentionally generic; it does not require that its
23.1.3.33 Array.prototype.toReversed ( )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let A be ?
ArrayCreate (len). - Let k be 0.
- Repeat, while k < len,
- Return A.
23.1.3.34 Array.prototype.toSorted ( comparefn )
This method performs the following steps when called:
- If comparefn is not
undefined andIsCallable (comparefn) isfalse , throw aTypeError exception. - Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let A be ?
ArrayCreate (len). - Let SortCompare be a new
Abstract Closure with parameters (x, y) that captures comparefn and performs the following steps when called:- Return ?
CompareArrayElements (x, y, comparefn).
- Return ?
- Let sortedList be ?
SortIndexedProperties (O, len, SortCompare,read-through-holes ). - Let j be 0.
- Repeat, while j < len,
- Perform !
CreateDataPropertyOrThrow (A, !ToString (𝔽 (j)), sortedList[j]). - Set j to j + 1.
- Perform !
- Return A.
23.1.3.35 Array.prototype.toSpliced ( start, skipCount, ...items )
This method performs the following steps when called:
- 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). - Let insertCount be the number of elements in items.
- If start is not present, then
- Let actualSkipCount be 0.
- Else if skipCount is not present, then
- Let actualSkipCount be len - actualStart.
- Else,
- Let sc be ?
ToIntegerOrInfinity (skipCount). - Let actualSkipCount be the result of
clamping sc between 0 and len - actualStart.
- Let sc be ?
- Let newLen be len + insertCount - actualSkipCount.
- If newLen > 253 - 1, throw a
TypeError exception. - Let A be ?
ArrayCreate (newLen). - Let i be 0.
- Let r be actualStart + actualSkipCount.
- Repeat, while i < actualStart,
- Let Pi be !
ToString (𝔽 (i)). - Let iValue be ?
Get (O, Pi). - Perform !
CreateDataPropertyOrThrow (A, Pi, iValue). - Set i to i + 1.
- Let Pi be !
- For each element E of items, do
- Let Pi be !
ToString (𝔽 (i)). - Perform !
CreateDataPropertyOrThrow (A, Pi, E). - Set i to i + 1.
- Let Pi be !
- Repeat, while i < newLen,
- Return A.
23.1.3.36 Array.prototype.toString ( )
This method performs the following steps when called:
- 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).
This method is intentionally generic; it does not require that its
23.1.3.37 Array.prototype.unshift ( ...items )
This method prepends the arguments 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.
It performs the following steps when called:
- 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 > 253 - 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 > 253 - 1, throw a
- Perform ?
Set (O,"length" ,𝔽 (len + argCount),true ). - Return
𝔽 (len + argCount).
The
This method is intentionally generic; it does not require that its
23.1.3.38 Array.prototype.values ( )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Return
CreateArrayIterator (O,value ).
23.1.3.39 Array.prototype.with ( index, value )
This method performs the following steps when called:
- Let O be ?
ToObject (this value). - Let len be ?
LengthOfArrayLike (O). - Let relativeIndex be ?
ToIntegerOrInfinity (index). - If relativeIndex ≥ 0, let actualIndex be relativeIndex.
- Else, let actualIndex be len + relativeIndex.
- If actualIndex ≥ len or actualIndex < 0, throw a
RangeError exception. - Let A be ?
ArrayCreate (len). - Let k be 0.
- Repeat, while k < len,
- Let Pk be !
ToString (𝔽 (k)). - If k is actualIndex, let fromValue be value.
- Else, let fromValue be ?
Get (O, Pk). - Perform !
CreateDataPropertyOrThrow (A, Pk, fromValue). - Set k to k + 1.
- Let Pk be !
- Return A.
23.1.3.40 Array.prototype [ @@iterator ] ( )
The initial value of the
23.1.3.41 Array.prototype [ @@unscopables ]
The initial value of the
- Let unscopableList be
OrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"at" ,true ). - 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,"findLast" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"findLastIndex" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"flat" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"flatMap" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"includes" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"keys" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"toReversed" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"toSorted" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"toSpliced" ,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.
The reason that
23.1.4 Properties of Array Instances
Array instances are
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 (an Object) and kind (
- 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
- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (array,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Let len be
TypedArrayLength (taRecord).
- Let taRecord be
- Else,
- Let len be ?
LengthOfArrayLike (array).
- Let len be ?
- If index ≥ len, return
NormalCompletion (undefined ). - Let indexNumber be
𝔽 (index). - If kind is
key , then- Let result be indexNumber.
- Else,
- Let elementKey be !
ToString (indexNumber). - Let elementValue be ?
Get (array, elementKey). - If kind is
value , then- Let result be elementValue.
- Else,
Assert : kind iskey+value .- Let result be
CreateArrayFromList (« indexNumber, elementValue »).
- Let elementKey be !
- Perform ?
GeneratorYield (CreateIterResultObject (result,false )). - 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]]: