22 Indexed Collections
22.1 Array Objects
Array objects are exotic objects that give special treatment to a certain class of property names. See
22.1.1 The Array Constructor
The Array constructor is the Array property of the global object. When called as a constructor it creates and initializes a new exotic Array object. When Array is called as a function rather than as a constructor, it also creates and initializes a new Array object. Thus the function call Array(…) is equivalent to the object creation expression new Array(…) with the same arguments.
The Array constructor is a single function whose behaviour is overloaded based upon the number and types of its arguments.
The Array constructor 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 a super call to the Array constructor to initialize subclass instances that are exotic Array objects. However, most of the Array.prototype methods are generic methods that are not dependent upon their this value being an exotic Array object.
The length property of the Array constructor function is 1.
22.1.1.1 Array ( )
This description applies if and only if the Array constructor is called with no arguments.
- Let numberOfArgs be the number of arguments passed to this function call.
- Assert: numberOfArgs = 0.
- If NewTarget is
undefined , let newTarget be the active function object, else let newTarget be NewTarget. - Let proto be
GetPrototypeFromConstructor (newTarget,"%ArrayPrototype%"). ReturnIfAbrupt (proto).- Return
ArrayCreate (0, proto).
22.1.1.2 Array (len)
This description applies if and only if the Array constructor is called with exactly one argument.
- Let numberOfArgs be the number of arguments passed to this function call.
- Assert: numberOfArgs = 1.
- If NewTarget is
undefined , let newTarget be the active function object, else let newTarget be NewTarget. - Let proto be
GetPrototypeFromConstructor (newTarget,"%ArrayPrototype%"). ReturnIfAbrupt (proto).- Let array be
ArrayCreate (0, proto). - If
Type (len) is not Number, then- Let defineStatus be
CreateDataProperty (array,"0", len). - Assert: defineStatus is
true . - Let intLen be 1.
- Let defineStatus be
- Else,
- Let intLen be
ToUint32 (len). - If intLen ≠ len, throw a
RangeError exception.
- Let intLen be
- Let setStatus be
Set (array,"length", intLen,true ). - Assert: setStatus is not an
abrupt completion . - Return array.
22.1.1.3 Array (...items )
This description applies if and only if the Array constructor is called with at least two arguments.
When the Array function is called the following steps are taken:
- Let numberOfArgs be the number of arguments passed to this function call.
- Assert: numberOfArgs ≥ 2.
- If NewTarget is
undefined , let newTarget be the active function object, else let newTarget be NewTarget. - Let proto be
GetPrototypeFromConstructor (newTarget,"%ArrayPrototype%"). ReturnIfAbrupt (proto).- Let array be
ArrayCreate (numberOfArgs, proto). ReturnIfAbrupt (array).- Let k be 0.
- Let items be a zero-origined
List containing the argument items in order. - Repeat, while k < numberOfArgs
- Let Pk be
ToString (k). - Let itemK be items[k].
- Let defineStatus be
CreateDataProperty (array, Pk, itemK). - Assert: defineStatus is
true . - Increase k by 1.
- Let Pk be
- Assert: the value of array's
lengthproperty is numberOfArgs. - Return array.
22.1.2 Properties of the Array Constructor
The value of the [[Prototype]] internal slot of the Array constructor is the intrinsic object
Besides the length property (whose value is 1), the Array constructor has the following properties:
22.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. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let mapping be
true
- If
- Let usingIterator be
GetMethod (items, @@iterator). ReturnIfAbrupt (usingIterator).- 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
ReturnIfAbrupt (A).- Let iterator be
GetIterator (items, usingIterator). ReturnIfAbrupt (iterator).- Let k be 0.
- Repeat
- Let Pk be
ToString (k). - Let next be
IteratorStep (iterator). ReturnIfAbrupt (next).- If next is
false , then- Let setStatus be
Set (A,"length", k,true ). ReturnIfAbrupt (setStatus).- Return A.
- Let setStatus be
- Let nextValue be
IteratorValue (next). ReturnIfAbrupt (nextValue).- If mapping is
true , then- Let mappedValue be
Call (mapfn, T, «nextValue, k»). - If mappedValue is an
abrupt completion , returnIteratorClose (iterator, mappedValue). - Let mappedValue be mappedValue.[[value]].
- Let mappedValue be
- Else, let mappedValue be nextValue.
- Let defineStatus be
CreateDataPropertyOrThrow (A, Pk, mappedValue). - If defineStatus is an
abrupt completion , returnIteratorClose (iterator, defineStatus). - Increase k by 1.
- Let Pk be
- If
- Assert: items is not an Iterable so assume it is an array-like object.
- Let arrayLike be
ToObject (items). ReturnIfAbrupt (arrayLike).- Let len be
ToLength (Get (arrayLike,"length")). ReturnIfAbrupt (len).- If
IsConstructor (C) istrue , then- Let A be
Construct (C, «len»).
- Let A be
- Else,
- Let A be
ArrayCreate (len).
- Let A be
ReturnIfAbrupt (A).- Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kValue be
Get (arrayLike, Pk). ReturnIfAbrupt (kValue).- If mapping is
true , then- Let mappedValue be
Call (mapfn, T, «kValue, k»). ReturnIfAbrupt (mappedValue).
- Let mappedValue be
- Else, let mappedValue be kValue.
- Let defineStatus be
CreateDataPropertyOrThrow (A, Pk, mappedValue). ReturnIfAbrupt (defineStatus).- Increase k by 1.
- Let Pk be
- Let setStatus be
Set (A,"length", len,true ). ReturnIfAbrupt (setStatus).- Return A.
The length property of the from method is 1.
The from function is an intentionally generic factory method; it does not require that its
22.1.2.2 Array.isArray ( arg )
The isArray function takes one argument arg, and performs the following steps:
- Return
IsArray (arg).
22.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 actual number of arguments passed to this function.
- Let items be the
List of arguments passed to this function. - Let C be the
this value. - If
IsConstructor (C) istrue , then- Let A be
Construct (C, «len»).
- Let A be
- Else,
- Let A be
ArrayCreate (len).
- Let A be
ReturnIfAbrupt (A).- Let k be 0.
- Repeat, while k < len
- Let kValue be items[k].
- Let Pk be
ToString (k). - Let defineStatus be
CreateDataPropertyOrThrow (A,Pk, kValue). ReturnIfAbrupt (defineStatus).- Increase k by 1.
- Let setStatus be
Set (A,"length", len,true ). ReturnIfAbrupt (setStatus).- Return A.
The length property of the of method is 0.
The items argument is assumed to be a well-formed rest argument value.
The of function is an intentionally generic factory method; it does not require that its
22.1.2.4 Array.prototype
The value of Array.prototype is
This property has the attributes { [[Writable]]:
22.1.2.5 get Array [ @@species ]
Array[@@species] is an accessor property whose set accessor function is
- Return the
this value.
The value of the name property of this function is "get [Symbol.species]".
Array prototype methods normally use their this object's constructor to create a derived object. However, a subclass constructor may over-ride that default behaviour by redefining its @@species property.
22.1.3 Properties of the Array Prototype Object
The Array prototype object is the intrinsic object length property whose initial value is 0 and whose attributes are
The value of the [[Prototype]] internal slot of the Array prototype object is the intrinsic object
The Array prototype object is specified to be an Array exotic object to ensure compatibility with ECMAScript code that was created prior to the ECMAScript 2015 specification.
22.1.3.1 Array.prototype.concat ( ...arguments )
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 in order.
The following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Let A be
ArraySpeciesCreate (O, 0). ReturnIfAbrupt (A).- Let n be 0.
- Let items be a
List whose first element is O and whose subsequent elements are, in left to right order, the arguments that were passed to this function invocation. - Repeat, while items is not empty
- Remove the first element from items and let E be the value of the element.
- Let spreadable be
IsConcatSpreadable (E). ReturnIfAbrupt (spreadable).- If spreadable is
true , then- Let k be 0.
- Let len be
ToLength (Get (E,"length")). ReturnIfAbrupt (len).- If n + len > 253-1, throw a
TypeError exception. - Repeat, while k < len
- Let P be
ToString (k). - Let exists be
HasProperty (E, P). ReturnIfAbrupt (exists).- If exists is
true , then- Let subElement be
Get (E, P). ReturnIfAbrupt (subElement).- Let status be
CreateDataPropertyOrThrow (A,ToString (n), subElement). ReturnIfAbrupt (status).
- Let subElement be
- Increase n by 1.
- Increase k by 1.
- Let P be
- Else E is added as a single item rather than spread,
- If n≥253-1, throw a
TypeError exception. - Let status be
CreateDataPropertyOrThrow (A,ToString (n), E). ReturnIfAbrupt (status).- Increase n by 1.
- If n≥253-1, throw a
- Let setStatus be
Set (A,"length", n,true ). ReturnIfAbrupt (setStatus).- Return A.
The length property of the concat method is 1.
The explicit setting of the length property in step 8 is necessary to ensure that its value is correct in situations where the trailing elements of the result Array are not present.
The concat function is intentionally generic; it does not require that its
22.1.3.1.1 Runtime Semantics: IsConcatSpreadable ( O )
The abstract operation IsConcatSpreadable with argument O performs the following steps:
- If
Type (O) is not Object, returnfalse . - Let spreadable be
Get (O, @@isConcatSpreadable). ReturnIfAbrupt (spreadable).- If spreadable is not
undefined , returnToBoolean (spreadable). - Return
IsArray (O).
22.1.3.2 Array.prototype.constructor
The initial value of Array.prototype.constructor is the intrinsic object
22.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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- Let relativeTarget be
ToInteger (target). ReturnIfAbrupt (relativeTarget).- If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to be min(relativeTarget, len).
- Let relativeStart be
ToInteger (start). ReturnIfAbrupt (relativeStart).- 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 beToInteger (end). ReturnIfAbrupt (relativeEnd).- 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
- Let direction be -1.
- Let from be from + count -1.
- Let to be to + count -1.
- Else,
- Let direction = 1.
- Repeat, while count > 0
- Let fromKey be
ToString (from). - Let toKey be
ToString (to). - Let fromPresent be
HasProperty (O, fromKey). ReturnIfAbrupt (fromPresent).- If fromPresent is
true , then- Let fromVal be
Get (O, fromKey). ReturnIfAbrupt (fromVal).- Let setStatus be
Set (O, toKey, fromVal,true ). ReturnIfAbrupt (setStatus).
- Let fromVal be
- Else fromPresent is
false ,- Let deleteStatus be
DeletePropertyOrThrow (O, toKey). ReturnIfAbrupt (deleteStatus).
- Let deleteStatus be
- Let from be from + direction.
- Let to be to + direction.
- Let count be count - 1.
- Let fromKey be
- Return O.
The length property of the copyWithin method is 2.
The copyWithin function is intentionally generic; it does not require that its
22.1.3.4 Array.prototype.entries ( )
The following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Return
CreateArrayIterator (O,"key+value").
22.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 the 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let testResult be
ToBoolean (Call (callbackfn, T, «kValue, k, O»)). ReturnIfAbrupt (testResult).- If testResult is
false , returnfalse .
- Let kValue be
- Increase k by 1.
- Let Pk be
- Return
true .
The length property of the every method is 1.
The every function is intentionally generic; it does not require that its
22.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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- Let relativeStart be
ToInteger (start). ReturnIfAbrupt (relativeStart).- 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 beToInteger (end). ReturnIfAbrupt (relativeEnd).- If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len).
- Repeat, while k < final
- Let Pk be
ToString (k). - Let setStatus be
Set (O, Pk, value,true ). ReturnIfAbrupt (setStatus).- Increase k by 1.
- Let Pk be
- Return O.
The length property of the fill method is 1.
The fill function is intentionally generic; it does not require that its
22.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 the 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let A be
ArraySpeciesCreate (O, 0). ReturnIfAbrupt (A).- Let k be 0.
- Let to be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let selected be
ToBoolean (Call (callbackfn, T, «kValue, k, O»)). ReturnIfAbrupt (selected).- If selected is
true , then- Let status be
CreateDataPropertyOrThrow (A,ToString (to), kValue). ReturnIfAbrupt (status).- Increase to by 1.
- Let status be
- Let kValue be
- Increase k by 1.
- Let Pk be
- Return A.
The length property of the filter method is 1.
The filter function is intentionally generic; it does not require that its
22.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 callbackfn. Elements that are appended to the array after the call to find begins will not be visited by callbackfn. 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.
When the find method is called, the following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If
IsCallable (predicate) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let testResult be
ToBoolean (Call (predicate, T, «kValue, k, O»)). ReturnIfAbrupt (testResult).- If testResult is
true , return kValue. - Increase k by 1.
- Let Pk be
- Return
undefined .
The length property of the find method is 1.
The find function is intentionally generic; it does not require that its
22.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 the 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 callbackfn. Elements that are appended to the array after the call to findIndex begins will not be visited by callbackfn. 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.
When the findIndex method is called with one or two arguments, the following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If
IsCallable (predicate) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let testResult be
ToBoolean (Call (predicate, T, «kValue, k, O»)). ReturnIfAbrupt (testResult).- If testResult is
true , return k. - Increase k by 1.
- Let Pk be
- Return -1.
The length property of the findIndex method is 1.
The findIndex function is intentionally generic; it does not require that its
22.1.3.10 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.
When the forEach method is called with one or two arguments, the following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let funcResult be
Call (callbackfn, T, «kValue, k, O»). ReturnIfAbrupt (funcResult).
- Let kValue be
- Increase k by 1.
- Let Pk be
- Return
undefined .
The length property of the forEach method is 1.
The forEach function is intentionally generic; it does not require that its
22.1.3.11 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 0 (i.e. the whole array is searched). If it is greater than or equal to the length of the array, -1 is returned, i.e. the array will not be searched. If it is negative, it is used as the offset from the end of the array to compute fromIndex. If the computed index is less than 0, the whole array will be searched.
When the indexOf method is called with one or two arguments, the following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If len is 0, return -1.
- If argument fromIndex was passed let n be
ToInteger (fromIndex); else let n be 0. ReturnIfAbrupt (n).- If n ≥ len, return -1.
- If n ≥ 0, then
- Let k be n.
- Else n<0,
- Let k be len - abs(n).
- If k < 0, let k be 0.
- Repeat, while k<len
- Let kPresent be
HasProperty (O,ToString (k)). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let elementK be
Get (O,ToString (k)). ReturnIfAbrupt (elementK).- Let same be the result of performing
Strict Equality Comparison searchElement === elementK. - If same is
true , return k.
- Let elementK be
- Increase k by 1.
- Let kPresent be
- Return -1.
The length property of the indexOf method is 1.
The indexOf function is intentionally generic; it does not require that its
22.1.3.12 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If separator is
undefined , let separator be the single-element String",". - Let sep be
ToString (separator). ReturnIfAbrupt (sep).- If len is zero, return the empty String.
- Let element0 be
Get (O,"0"). - If element0 is
undefined ornull , let R be the empty String; otherwise, let R beToString (element0). ReturnIfAbrupt (R).- Let k be
1. - Repeat, while k < len
- Let S be the String value produced by concatenating R and sep.
- Let element be
Get (O,ToString (k)). - If element is
undefined ornull , let next be the empty String; otherwise, let next beToString (element). ReturnIfAbrupt (next).- Let R be a String value produced by concatenating S and next.
- Increase k by 1.
- Return R.
The length property of the join method is 1.
The join function is intentionally generic; it does not require that its
22.1.3.13 Array.prototype.keys ( )
The following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Return
CreateArrayIterator (O,"key").
22.1.3.14 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 negative, it is used as the offset from the end of the array to compute fromIndex. If the computed index is less than 0, -1 is returned.
When the lastIndexOf method is called with one or two arguments, the following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If len is 0, return -1.
- If argument fromIndex was passed let n be
ToInteger (fromIndex); else let n be len-1. ReturnIfAbrupt (n).- If n ≥ 0, let k be min(n, len - 1).
- Else n < 0,
- Let k be len - abs(n).
- Repeat, while k≥ 0
- Let kPresent be
HasProperty (O,ToString (k)). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let elementK be
Get (O,ToString (k)). ReturnIfAbrupt (elementK).- Let same be the result of performing
Strict Equality Comparison searchElement === elementK. - If same is
true , return k.
- Let elementK be
- Decrease k by 1.
- Let kPresent be
- Return -1.
The length property of the lastIndexOf method is 1.
The lastIndexOf function is intentionally generic; it does not require that its
22.1.3.15 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let A be
ArraySpeciesCreate (O, len). ReturnIfAbrupt (A).- Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let mappedValue be
Call (callbackfn, T, «kValue, k, O»). ReturnIfAbrupt (mappedValue).- Let status be
CreateDataPropertyOrThrow (A, Pk, mappedValue). ReturnIfAbrupt (status).
- Let kValue be
- Increase k by 1.
- Let Pk be
- Return A.
The length property of the map method is 1.
The map function is intentionally generic; it does not require that its
22.1.3.16 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If len is zero,
- Let setStatus be
Set (O,"length", 0,true ). ReturnIfAbrupt (setStatus).- Return
undefined .
- Let setStatus be
- Else len > 0,
- Let newLen be len-1.
- Let indx be
ToString (newLen). - Let element be
Get (O, indx). ReturnIfAbrupt (element).- Let deleteStatus be
DeletePropertyOrThrow (O, indx). ReturnIfAbrupt (deleteStatus).- Let setStatus be
Set (O,"length", newLen,true ). ReturnIfAbrupt (setStatus).- Return element.
The pop function is intentionally generic; it does not require that its
22.1.3.17 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- Let items be a
List whose elements are, in left to right order, the arguments that were passed to this function invocation. - Let argCount be the number of elements in items.
- If len + argCount > 253-1, throw a
TypeError exception. - Repeat, while items is not empty
- Remove the first element from items and let E be the value of the element.
- Let setStatus be
Set (O,ToString (len), E,true ). ReturnIfAbrupt (setStatus).- Let len be len+1.
- Let setStatus be
Set (O,"length", len,true ). ReturnIfAbrupt (setStatus).- Return len.
The length property of the push method is 1.
The push function is intentionally generic; it does not require that its
22.1.3.18 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 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 provided 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 provided, 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - If len is 0 and initialValue is not present, throw a
TypeError exception. - Let k be 0.
- If initialValue is present, then
- Set accumulator to initialValue.
- Else initialValue is not present,
- Let kPresent be
false . - Repeat, while kPresent is
false and k < len- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let accumulator be
Get (O, Pk). ReturnIfAbrupt (accumulator).
- Let accumulator be
- Increase k by 1.
- Let Pk be
- If kPresent is
false , throw aTypeError exception.
- Let kPresent be
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let accumulator be
Call (callbackfn,undefined , «accumulator, kValue, k, O»). ReturnIfAbrupt (accumulator).
- Let kValue be
- Increase k by 1.
- Let Pk be
- Return accumulator.
The length property of the reduce method is 1.
The reduce function is intentionally generic; it does not require that its
22.1.3.19 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 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 provided 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 provided, then previousValue will be equal to the last value in the array and currentValue will be equal to 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.
When the reduceRight method is called with one or two arguments, the following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- 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.
- If initialValue is present, then
- Set accumulator to initialValue.
- Else initialValue is not present,
- Let kPresent be
false . - Repeat, while kPresent is
false and k ≥ 0- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let accumulator be
Get (O, Pk). ReturnIfAbrupt (accumulator).
- Let accumulator be
- Decrease k by 1.
- Let Pk be
- If kPresent is
false , throw aTypeError exception.
- Let kPresent be
- Repeat, while k ≥ 0
- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let accumulator be
Call (callbackfn,undefined , «accumulator, kValue, k, »). ReturnIfAbrupt (accumulator).
- Let kValue be
- Decrease k by 1.
- Let Pk be
- Return accumulator.
The length property of the reduceRight method is 1.
The reduceRight function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.
22.1.3.20 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- 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). ReturnIfAbrupt (lowerExists).- If lowerExists is
true , then- Let lowerValue be
Get (O, lowerP). ReturnIfAbrupt (lowerValue).
- Let lowerValue be
- Let upperExists be
HasProperty (O, upperP). ReturnIfAbrupt (upperExists).- If upperExists is
true , then- Let upperValue be
Get (O, upperP). ReturnIfAbrupt (upperValue).
- Let upperValue be
- If lowerExists is
true and upperExists istrue , then- Let setStatus be
Set (O, lowerP, upperValue,true ). ReturnIfAbrupt (setStatus).- Let setStatus be
Set (O, upperP, lowerValue,true ). ReturnIfAbrupt (setStatus).
- Let setStatus be
- Else if lowerExists is
false and upperExists istrue , then- Let setStatus be
Set (O, lowerP, upperValue,true ). ReturnIfAbrupt (setStatus).- Let deleteStatus be
DeletePropertyOrThrow (O, upperP). ReturnIfAbrupt (deleteStatus).
- Let setStatus be
- Else if lowerExists is
true and upperExists isfalse , then- Let deleteStatus be
DeletePropertyOrThrow (O, lowerP). ReturnIfAbrupt (deleteStatus).- Let setStatus be
Set (O, upperP, lowerValue,true ). ReturnIfAbrupt (setStatus).
- Let deleteStatus be
- Else both lowerExists and upperExists are
false ,- No action is required.
- Increase lower by 1.
- Return O .
The reverse function is intentionally generic; it does not require that its
22.1.3.21 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If len is zero, then
- Let setStatus be
Set (O,"length", 0,true ). ReturnIfAbrupt (setStatus).- Return
undefined .
- Let setStatus be
- Let first be
Get (O,"0"). ReturnIfAbrupt (first).- 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). ReturnIfAbrupt (fromPresent).- If fromPresent is
true , then- Let fromVal be
Get (O, from). ReturnIfAbrupt (fromVal).- Let setStatus be
Set (O, to, fromVal,true ). ReturnIfAbrupt (setStatus).
- Let fromVal be
- Else fromPresent is
false ,- Let deleteStatus be
DeletePropertyOrThrow (O, to). ReturnIfAbrupt (deleteStatus).
- Let deleteStatus be
- Increase k by 1.
- Let from be
- Let deleteStatus be
DeletePropertyOrThrow (O,ToString (len-1)). ReturnIfAbrupt (deleteStatus).- Let setStatus be
Set (O,"length", len-1,true ). ReturnIfAbrupt (setStatus).- Return first.
The shift function is intentionally generic; it does not require that its
22.1.3.22 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- Let relativeStart be
ToInteger (start). ReturnIfAbrupt (relativeStart).- 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 beToInteger (end). ReturnIfAbrupt (relativeEnd).- 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). ReturnIfAbrupt (A).- Let n be 0.
- Repeat, while k < final
- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let status be
CreateDataPropertyOrThrow (A,ToString (n), kValue ). ReturnIfAbrupt (status).
- Let kValue be
- Increase k by 1.
- Increase n by 1.
- Let Pk be
- Let setStatus be
Set (A,"length", n,true ). ReturnIfAbrupt (setStatus).- Return A.
The length property of the slice method is 2.
The explicit setting of the length property of the result Array in step 16 is necessary to ensure that its value is correct in situations where the trailing elements of the result Array are not present.
The slice function is intentionally generic; it does not require that its
22.1.3.23 Array.prototype.some ( callbackfn [ , thisArg ] )
callbackfn should be a function that accepts three arguments and returns a value that is coercible to the 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kPresent be
HasProperty (O, Pk). ReturnIfAbrupt (kPresent).- If kPresent is
true , then- Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let testResult be
ToBoolean (Call (callbackfn, T, «kValue, k, and O»)). ReturnIfAbrupt (testResult).- If testResult is
true , returntrue .
- Let kValue be
- Increase k by 1.
- Let Pk be
- Return
false .
The length property of the some method is 1.
The some function is intentionally generic; it does not require that its
22.1.3.24 Array.prototype.sort (comparefn)
The elements of this array are sorted. The sort is not necessarily stable (that is, elements that compare equal do not necessarily remain in their original order). If comparefn is not
Upon entry, the following steps are performed to initialize evaluation of the sort function:
- Let obj be
ToObject (this value). - Let len be
ToLength (Get (obj,"length")). ReturnIfAbrupt (len).
Within this specification of the sort method, an object, obj, is said to be sparse if the following algorithm returns
- For each integer i in the range 0≤i< len
- Let elem be obj.[[GetOwnProperty]](
ToString (i)). - If elem is
undefined , returntrue .
- Let elem be obj.[[GetOwnProperty]](
- Return
false .
The sort order is the ordering, after completion of this function, of the integer indexed property values of obj whose integer indexes are less than len. The result of the sort function is then determined as follows:
If comparefn is not
Let proto be obj.[[GetPrototypeOf]](). If proto is not
- obj is sparse
- 0 ≤ j < len
-
HasProperty (proto,ToString (j)) istrue .
The sort order is also implementation defined if obj is sparse and any of the following conditions are true:
-
IsExtensible (obj) isfalse . -
Any integer index property of obj whose name is a nonnegative integer less than len is a data property whose [[Configurable]] attribute is
false .
The sort order is also implementation defined if any of the following conditions are true:
- If obj is an exotic object (including Proxy exotic objects) whose behaviour for [[Get]], [[Set]], [[Delete]], and [[GetOwnProperty]] is not the ordinary object implementation of these internal methods.
-
If any index index property of obj whose name is a nonnegative integer less than len is an accessor property or is a data property whose [[Writable]] attribute is
false . -
If comparefn is
undefined and the application ofToString to any value passed as an argument toSortCompare modifies obj or any object on obj's prototype chain. -
If comparefn is
undefined and all applications ofToString , to any specific value passed as an argument toSortCompare , do not produce the same result.
The following steps are taken:
- Perform an implementation-dependent sequence of calls to the [[Get]] and [[Set]] internal methods of obj, to the
DeletePropertyOrThrow andHasOwnProperty abstract operation with obj as the first argument, and toSortCompare (described below), such that:- The property key argument for each call to [[Get]], [[Set]],
HasOwnProperty , orDeletePropertyOrThrow is the string representation of a nonnegative integer less than len. - The arguments for calls to
SortCompare are values returned by a previous call to the [[Get]] internal method, unless the properties accessed by those previous calls did not exist according toHasOwnProperty . If both perspective arguments toSortCompare correspond to non-existent properties, use +0 instead of callingSortCompare . If only the first perspective argument is non-existent use +1. If only the second perspective argument is non-existent use -1. - If obj is not sparse then
DeletePropertyOrThrow must not be called. - If any [[Set]] call returns
false aTypeError exception is thrown. - If an
abrupt completion is returned from any of these operations, it is immediately returned as the value of this function.
- The property key argument for each call to [[Get]], [[Set]],
- Return obj.
Unless the sort order is specified above to be implementation-defined, the returned object must have the following two characteristics:
-
There must be some mathematical permutation π of the nonnegative integers less than len, such that for every nonnegative integer j less than len, if property
old[j] existed, thennew[π(j)] is exactly the same value asold[j] . But if propertyold[j] did not exist, thennew[π(j)] does not exist. -
Then for all nonnegative integers j and k, each less than len, if
(seeSortCompare (old[j], old[k]) < 0SortCompare below), thennew[π(j)] < new[π(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 not NaN. 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
22.1.3.24.1 Runtime Semantics: SortCompare( x, y )
The SortCompare abstract operation is called with two arguments x and y. It also has access to the comparefn argument passed to the current invocation of the sort method. The following steps are taken:
- If x and y are both
undefined , return +0. - If x is
undefined , return 1. - If y is
undefined , return -1. - If the argument comparefn is not
undefined , then- Let v be
ToNumber (Call (comparefn,undefined , «x, y»)). ReturnIfAbrupt (v).- If v is
NaN , return +0. - Return v.
- Let v be
- Let xString be
ToString (x). ReturnIfAbrupt (xString).- Let yString be
ToString (y). ReturnIfAbrupt (yString).- If xString < yString, return -1.
- If xString > yString, return 1.
- Return +0.
Because non-existent property values always compare greater than
Method calls performed by the
22.1.3.25 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 integer index start are replaced by the arguments items. An Array object containing the deleted elements (if any) is returned.
The following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- Let relativeStart be
ToInteger (start). ReturnIfAbrupt (relativeStart).- If relativeStart < 0, let actualStart be max((len + relativeStart),0); else let actualStart be min(relativeStart, len).
- If the number of actual arguments is 0, then
- Let insertCount be 0.
- Let actualDeleteCount be 0.
- Else if the number of actual arguments is 1, then
- Let insertCount be 0.
- Let actualDeleteCount be len - actualStart.
- Else,
- Let insertCount be the number of actual arguments minus 2.
- Let dc be
ToInteger (deleteCount). ReturnIfAbrupt (dc).- Let actualDeleteCount be min(max(dc,0), len - actualStart).
- If len+insertCount-actualDeleteCount > 253-1, throw a
TypeError exception. - Let A be
ArraySpeciesCreate (O, actualDeleteCount). ReturnIfAbrupt (A).- Let k be 0.
- Repeat, while k < actualDeleteCount
- Let from be
ToString (actualStart+k). - Let fromPresent be
HasProperty (O, from). ReturnIfAbrupt (fromPresent).- If fromPresent is
true , then- Let fromValue be
Get (O, from). ReturnIfAbrupt (fromValue).- Let status be
CreateDataPropertyOrThrow (A,ToString (k), fromValue). ReturnIfAbrupt (status).
- Let fromValue be
- Increment k by 1.
- Let from be
- Let setStatus be
Set (A,"length", actualDeleteCount,true ). ReturnIfAbrupt (setStatus).- Let items be a
List whose elements are, in left to right order, the portion of the actual argument list starting with the third argument. The list is empty if fewer than three arguments were passed. - Let itemCount be the number of elements in items.
- If itemCount < actualDeleteCount, then
- Let k be actualStart.
- Repeat, while k < (len - actualDeleteCount)
- Let from be
ToString (k+actualDeleteCount). - Let to be
ToString (k+itemCount). - Let fromPresent be
HasProperty (O, from). ReturnIfAbrupt (fromPresent).- If fromPresent is
true , then- Let fromValue be
Get (O, from). ReturnIfAbrupt (fromValue).- Let setStatus be
Set (O, to, fromValue,true ). ReturnIfAbrupt (setStatus).
- Let fromValue be
- Else fromPresent is
false ,- Let deleteStatus be
DeletePropertyOrThrow (O, to). ReturnIfAbrupt (deleteStatus).
- Let deleteStatus be
- Increase k by 1.
- Let from be
- Let k be len.
- Repeat, while k > (len - actualDeleteCount + itemCount)
- Let deleteStatus be
DeletePropertyOrThrow (O,ToString (k-1)). ReturnIfAbrupt (deleteStatus).- Decrease k by 1.
- Let deleteStatus be
- Else if itemCount > actualDeleteCount, then
- Let k be (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). ReturnIfAbrupt (fromPresent).- If fromPresent is
true , then- Let fromValue be
Get (O, from). ReturnIfAbrupt (fromValue).- Let setStatus be
Set (O, to, fromValue,true ). ReturnIfAbrupt (setStatus).
- Let fromValue be
- Else fromPresent is
false ,- Let deleteStatus be
DeletePropertyOrThrow (O, to). ReturnIfAbrupt (deleteStatus).
- Let deleteStatus be
- Decrease k by 1.
- Let from be
- Let k be actualStart.
- Repeat, while items is not empty
- Remove the first element from items and let E be the value of that element.
- Let setStatus be
Set (O,ToString (k), E,true ). ReturnIfAbrupt (setStatus).- Increase k by 1.
- Let setStatus be
Set (O,"length", len - actualDeleteCount + itemCount,true ). ReturnIfAbrupt (setStatus).- Return A.
The length property of the splice method is 2.
The explicit setting of the length property of the result Array in step 24 is necessary to ensure that its value is correct in situations where its trailing elements are not present.
The splice function is intentionally generic; it does not require that its
22.1.3.26 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the Array.prototype.toLocaleString method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the toLocaleString method is used.
The first edition of ECMA-402 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 ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.
The following steps are taken:
- Let array be
ToObject (this value). ReturnIfAbrupt (array).- Let len be
ToLength (Get (array,"length")). ReturnIfAbrupt (len).- Let separator be the String value for the list-separator String appropriate for the host environment's current locale (this is derived in an implementation-defined way).
- If len is zero, return the empty String.
- Let firstElement be
Get (array,"0"). ReturnIfAbrupt (firstElement).- If firstElement is
undefined ornull , then- Let R be the empty String.
- Else
- Let R be
ToString (Invoke (firstElement,"toLocaleString")). ReturnIfAbrupt (R).
- Let R be
- Let k be
1. - Repeat, while k < len
- Let S be a String value produced by concatenating R and separator.
- Let nextElement be
Get (array,ToString (k)). ReturnIfAbrupt (nextElement).- If nextElement is
undefined ornull , then- Let R be the empty String.
- Else
- Let R be
ToString (Invoke (nextElement,"toLocaleString")). ReturnIfAbrupt (R).
- Let R be
- Let R be a String value produced by concatenating S and R.
- Increase k by 1.
- 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 implementation-defined locale-specific way. The result of calling this function is intended to be analogous to the result of toString, except that the result of this function is intended to be locale-specific.
The toLocaleString function is intentionally generic; it does not require that its
22.1.3.27 Array.prototype.toString ( )
When the toString method is called, the following steps are taken:
- Let array be
ToObject (this value). ReturnIfAbrupt (array).- Let func be
Get (array,"join"). ReturnIfAbrupt (func).- If
IsCallable (func) isfalse , let func be the intrinsic function %ObjProto_toString% (19.1.3.6 ). - Return
Call (func, array).
The toString function is intentionally generic; it does not require that its
22.1.3.28 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). ReturnIfAbrupt (O).- Let len be
ToLength (Get (O,"length")). ReturnIfAbrupt (len).- Let argCount be the number of actual arguments.
- 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). ReturnIfAbrupt (fromPresent).- If fromPresent is
true , then- Let fromValue be
Get (O, from). ReturnIfAbrupt (fromValue).- Let setStatus be
Set (O, to, fromValue,true ). ReturnIfAbrupt (setStatus).
- Let fromValue be
- Else fromPresent is
false ,- Let deleteStatus be
DeletePropertyOrThrow (O, to). ReturnIfAbrupt (deleteStatus).
- Let deleteStatus be
- Decrease k by 1.
- Let from be
- Let j be 0.
- Let items be a
List whose elements are, in left to right order, the arguments that were passed to this function invocation. - Repeat, while items is not empty
- Remove the first element from items and let E be the value of that element.
- Let setStatus be
Set (O,ToString (j), E,true ). ReturnIfAbrupt (setStatus).- Increase j by 1.
- If len+ argCount > 253-1, throw a
- Let setStatus be
Set (O,"length", len+argCount,true ). ReturnIfAbrupt (setStatus).- Return len+argCount.
The length property of the unshift method is 1.
The unshift function is intentionally generic; it does not require that its
22.1.3.29 Array.prototype.values ( )
The following steps are taken:
- Let O be
ToObject (this value). ReturnIfAbrupt (O).- Return
CreateArrayIterator (O,"value").
This function is the %ArrayProto_values% intrinsic object.
22.1.3.30 Array.prototype [ @@iterator ] ( )
The initial value of the @@iterator property is the same function object as the initial value of the Array.prototype.values property.
22.1.3.31 Array.prototype [ @@unscopables ]
The initial value of the @@unscopables data property is an object created by the following steps:
- Let blackList be
ObjectCreate (null ). - Perform
CreateDataProperty (blackList,"copyWithin",true ). - Perform
CreateDataProperty (blackList,"entries",true ). - Perform
CreateDataProperty (blackList,"fill",true ). - Perform
CreateDataProperty (blackList,"find",true ). - Perform
CreateDataProperty (blackList,"findIndex",true ). - Perform
CreateDataProperty (blackList,"keys",true ). - Perform
CreateDataProperty (blackList,"values",true ). - Assert: Each of the above calls will return
true . - Return blackList.
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.
22.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 prototype object.
Array instances have a length property, and a set of enumerable properties with array index names.
22.1.4.1 length
The length property of an Array instance is a data property whose value is always numerically greater than the name of every configurable own property whose name is an array index.
The length property initially has the attributes
Reducing the value of the length property has the side-effect of deleting own array elements whose array index is between the old and new length values. However, non-configurable properties can not be deleted. Attempting to set the length property of an Array object to a value that is numerically less than or equal to the largest numeric own property name of an existing non-configurable array indexed property of the array will result in the length being set to a numeric value that is one greater than that non-configurable numeric own property name. See
22.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 constructor for Array Iterator objects. Instead, Array iterator objects are created by calling certain methods of Array instance objects.
22.1.5.1 CreateArrayIterator Abstract Operation
Several methods of Array objects return Iterator objects. The abstract operation CreateArrayIterator with arguments array and kind is used to create such iterator objects. It performs the following steps:
- Assert:
Type (array) is Object. - Let iterator be
ObjectCreate (%ArrayIteratorPrototype% , «[[IteratedObject]], [[ArrayIteratorNextIndex]], [[ArrayIterationKind]]»). - Set iterator's [[IteratedObject]] internal slot to array.
- Set iterator's [[ArrayIteratorNextIndex]] internal slot to 0.
- Set iterator's [[ArrayIterationKind]] internal slot to kind.
- Return iterator.
22.1.5.2 The %ArrayIteratorPrototype% Object
All Array Iterator Objects inherit properties from the
22.1.5.2.1 %ArrayIteratorPrototype% .next( )
- Let O be the
this value. - If
Type (O) is not Object, throw aTypeError exception. - If O does not have all of the internal slots of an Array Iterator Instance (
22.1.5.3 ), throw aTypeError exception. - Let a be the value of the [[IteratedObject]] internal slot of O.
- If a is
undefined , returnCreateIterResultObject (undefined ,true ). - Let index be the value of the [[ArrayIteratorNextIndex]] internal slot of O.
- Let itemKind be the value of the [[ArrayIterationKind]] internal slot of O.
- If a has a [[TypedArrayName]] internal slot, then
- Let len be the value of O's [[ArrayLength]] internal slot.
- Else,
- Let len be
ToLength (Get (a,"length")). ReturnIfAbrupt (len).
- Let len be
- If index ≥ len, then
- Set the value of the [[IteratedObject]] internal slot of O to
undefined . - Return
CreateIterResultObject (undefined ,true ).
- Set the value of the [[IteratedObject]] internal slot of O to
- Set the value of the [[ArrayIteratorNextIndex]] internal slot of O to index+1.
- If itemKind is
"key", returnCreateIterResultObject (index,false ). - Let elementKey be
ToString (index). - Let elementValue be
Get (a, elementKey). ReturnIfAbrupt (elementValue).- If itemKind is
"value", let result be elementValue. - Else,
- Assert: itemKind is
"key+value". - Let result be
CreateArrayFromList («index, elementValue»).
- Assert: itemKind is
- Return
CreateIterResultObject (result,false ).
22.1.5.2.2 %ArrayIteratorPrototype% [ @@toStringTag ]
The initial value of the @@toStringTag property is the String value "Array Iterator".
This property has the attributes { [[Writable]]:
22.1.5.3 Properties of Array Iterator Instances
Array Iterator instances are ordinary objects that inherit properties from the
| Internal Slot | Description |
|---|---|
| [[IteratedObject]] | The object whose array elements are being iterated. |
| [[ArrayIteratorNextIndex]] | The integer index of the next integer index to be examined by this iteration. |
| [[ArrayIterationKind]] |
A String value that identifies what is returned for each element of the iteration. The possible values are: "key", "value", "key+value".
|
22.2 TypedArray Objects
TypedArray objects present an array-like view of an underlying binary data buffer (
| Constructor Name and Intrinsic | Element Type | Element Size | Conversion Operation | Description | Equivalent C Type |
|---|---|---|---|---|---|
|
Int8Array
|
Int8 | 1 |
|
8-bit 2's complement signed integer | signed char |
|
Uint8Array
|
Uint8 | 1 |
|
8-bit unsigned integer | unsigned char |
|
Uint8ClampedArray
|
Uint8C | 1 |
|
8-bit unsigned integer (clamped conversion) | unsigned char |
|
Int16Array
|
Int16 | 2 |
|
16-bit 2's complement signed integer | short |
|
Uint16Array
|
Uint16 | 2 |
|
16-bit unsigned integer | unsigned short |
|
Int32Array
|
Int32 | 4 |
|
32-bit 2's complement signed integer | int |
|
Uint32Array
|
Uint32 | 4 |
|
32-bit unsigned integer | unsigned int |
|
Float32Array
|
Float32 | 4 | 32-bit IEEE floating point | float | |
|
Float64Array
|
Float64 | 8 | 64-bit IEEE floating point | double |
In the definitions below, references to TypedArray should be replaced with the appropriate constructor name from the above table. The phrase “the element size in bytes” refers to the value in the Element Size column of the table in the row corresponding to the constructor. The phrase “element Type” refers to the value in the Element Type column for that row.
22.2.1 The %TypedArray% Intrinsic Object
The
The super call. The new expression an exception is thrown.
The super call of
22.2.1.1 %TypedArray% ( )
This description applies only if the
- If NewTarget is
undefined , throw aTypeError exception. - Return
AllocateTypedArray (NewTarget, 0).
22.2.1.2 %TypedArray% ( length )
This description applies only if the
- Assert:
Type (length) is not Object. - If NewTarget is
undefined , throw aTypeError exception. - If length is
undefined , throw aTypeError exception. - Let numberLength be
ToNumber (length). - Let elementLength be
ToLength (numberLength). ReturnIfAbrupt (elementLength).- If
SameValueZero (numberLength, elementLength) isfalse , throw aRangeError exception. - Return
AllocateTypedArray (NewTarget, elementLength).
22.2.1.2.1 Runtime Semantics: AllocateTypedArray (newTarget, length )
The abstract operation AllocateTypedArray with argument newTarget and optional argument length is used to validate and create an instance of a TypedArray constructor. If the length argument is passed an ArrayBuffer of that length is also allocated and associated with the new TypedArray instance. AllocateTypedArray provides common semantics that is used by all of the
- Assert:
IsConstructor (newTarget) istrue . - If
SameValue (%TypedArray% , newTarget) istrue , throw aTypeError exception. - NOTE
%TypedArray% throws an exception when invoked via either a function call or thenewoperator. It can only be successfully invoked by aSuperCall . - Let constructorName be
undefined . - Let subclass be newTarget.
- Repeat while constructorName is
undefined - If subclass is
null , throw aTypeError exception. - If
SameValue (%TypedArray% , subclass) istrue , throw aTypeError exception. - If subclass has a [[TypedArrayConstructorName]] internal slot, let constructorName be the value of subclass's [[TypedArrayConstructorName]] internal slot.
- Let subclass be subclass.[[GetPrototypeOf]]().
ReturnIfAbrupt (subclass).
- If subclass is
- Let proto be
GetPrototypeFromConstructor (newTarget,"%TypedArrayPrototype%"). ReturnIfAbrupt (proto).- Let obj be
IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). - Assert: The [[ViewedArrayBuffer]] internal slot of obj is
undefined . - Set obj's [[TypedArrayName]] internal slot to constructorName.
- If length was not passed, then
- Set obj's [[ByteLength]] internal slot to 0.
- Set obj's [[ByteOffset]] internal slot to 0.
- Set obj's [[ArrayLength]] internal slot to 0.
- Else,
- Let elementSize be the Element Size value in
Table 49 for constructorName. - Let byteLength be elementSize × length.
- Let data be
AllocateArrayBuffer (%ArrayBuffer% , byteLength). ReturnIfAbrupt (data).- Set obj's [[ViewedArrayBuffer]] internal slot to data.
- Set obj's [[ByteLength]] internal slot to byteLength.
- Set obj's [[ByteOffset]] internal slot to 0.
- Set obj's [[ArrayLength]] internal slot to length.
- Let elementSize be the Element Size value in
- Return obj.
22.2.1.3 %TypedArray% ( typedArray )
This description applies only if the
- Assert:
Type (typedArray) is Object and typedArray has a [[TypedArrayName]] internal slot. - If NewTarget is
undefined , throw aTypeError exception. - Let O be
AllocateTypedArray (NewTarget). ReturnIfAbrupt (O).- Let srcArray be typedArray.
- Let srcData be the value of srcArray's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (srcData) istrue , throw aTypeError exception. - Let constructorName be the String value of O's [[TypedArrayName]] internal slot.
- Let elementType be the String value of the Element Type value in
Table 49 for constructorName. - Let elementLength be the value of srcArray's [[ArrayLength]] internal slot.
- Let srcName be the String value of srcArray's [[TypedArrayName]] internal slot.
- Let srcType be the String value of the Element Type value in
Table 49 for srcName. - Let srcElementSize be the Element Size value in
Table 49 for srcName. - Let srcByteOffset be the value of srcArray's [[ByteOffset]] internal slot.
- Let elementSize be the Element Size value in
Table 49 for constructorName. - Let byteLength be elementSize × elementLength.
- If
SameValue (elementType,srcType) istrue , then- Let data be
CloneArrayBuffer (srcData, srcByteOffset). ReturnIfAbrupt (data).
- Let data be
- Else,
- Let bufferConstructor be
SpeciesConstructor (srcData,%ArrayBuffer% ). ReturnIfAbrupt (bufferConstructor).- Let data be
AllocateArrayBuffer (bufferConstructor, byteLength). ReturnIfAbrupt (data).- If
IsDetachedBuffer (srcData) istrue , throw aTypeError exception. - Let srcByteIndex be srcByteOffset.
- Let targetByteIndex be 0.
- Let count be elementLength.
- Repeat, while count >0
- Let value be
GetValueFromBuffer (srcData, srcByteIndex, srcType). - Perform
SetValueInBuffer (data, targetByteIndex, elementType, value). - Set srcByteIndex to srcByteIndex + srcElementSize.
- Set targetByteIndex to targetByteIndex + elementSize.
- Decrement count by 1.
- Let value be
- Let bufferConstructor be
- Set O's [[ViewedArrayBuffer]] internal slot to data.
- Set O's [[ByteLength]] internal slot to byteLength.
- Set O's [[ByteOffset]] internal slot to 0.
- Set O's [[ArrayLength]] internal slot to elementLength.
- Return O.
22.2.1.4 %TypedArray% ( object )
This description applies only if the
- Assert:
Type (object) is Object and object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] internal slot. - If NewTarget is
undefined , throw aTypeError exception. - Return
TypedArrayFrom (NewTarget, object,undefined ,undefined ).
22.2.1.5 %TypedArray% ( buffer [ , byteOffset [ , length ] ] )
This description applies only if the
- Assert:
Type (buffer) is Object and buffer has an [[ArrayBufferData]] internal slot. - If NewTarget is
undefined , throw aTypeError exception. - Let O be
AllocateTypedArray (NewTarget). ReturnIfAbrupt (O).- Let constructorName be the String value of O's [[TypedArrayName]] internal slot.
- Let elementSize be the Number value of the Element Size value in
Table 49 for constructorName. - Let offset be
ToInteger (byteOffset). ReturnIfAbrupt (offset).- If offset < 0, throw a
RangeError exception. - If offset modulo elementSize ≠ 0, throw a
RangeError exception. - If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]] internal slot.
- If length is
undefined , then- If bufferByteLength modulo elementSize ≠ 0, throw a
RangeError exception. - Let newByteLength be bufferByteLength - offset.
- If newByteLength < 0, throw a
RangeError exception.
- If bufferByteLength modulo elementSize ≠ 0, throw a
- Else,
- Let newLength be
ToLength (length). ReturnIfAbrupt (newLength).- Let newByteLength be newLength × elementSize.
- If offset+newByteLength > bufferByteLength, throw a
RangeError exception.
- Let newLength be
- Set O's [[ViewedArrayBuffer]] internal slot to buffer.
- Set O's [[ByteLength]] internal slot to newByteLength.
- Set O's [[ByteOffset]] internal slot to offset.
- Set O's [[ArrayLength]] internal slot to newByteLength / elementSize .
- Return O.
22.2.2 Properties of the %TypedArray% Intrinsic Object
The value of the [[Prototype]] internal slot of
Besides a length property whose value is 3 and a name property whose value is "TypedArray",
22.2.2.1 %TypedArray% .from ( source [ , mapfn [ , thisArg ] ] )
When the from method is called with argument source, and optional arguments mapfn and thisArg, the following steps are taken:
- Let C be the
this value. - If
IsConstructor (C) isfalse , throw aTypeError exception. - If mapfn was supplied, let f be mapfn; otherwise let f be
undefined . - If f is not
undefined , then- If
IsCallable (f) isfalse , throw aTypeError exception.
- If
- If thisArg was supplied, let t be thisArg; else let t be
undefined . - Return
TypedArrayFrom (C, source, f, t).
The length property of the from method is 1.
22.2.2.1.1 Runtime Semantics: TypedArrayFrom( constructor, items, mapfn, thisArg )
When the TypedArrayFrom abstract operation is called with arguments constructor, items, mapfn, and thisArg, the following steps are taken:
- Let C be constructor.
- Assert:
IsConstructor (C) istrue . - Assert: mapfn is either a callable Object or
undefined . - If mapfn is
undefined , let mapping befalse . - Else
- Let T be thisArg.
- Let mapping be
true
- Let usingIterator be
GetMethod (items, @@iterator). ReturnIfAbrupt (usingIterator).- If usingIterator is not
undefined , then- Let iterator be
GetIterator (items, usingIterator). ReturnIfAbrupt (iterator).- Let values be a new empty
List . - Let next be
true . - Repeat, while next is not
false - Let next be
IteratorStep (iterator). ReturnIfAbrupt (next).- If next is not
false , then- Let nextValue be
IteratorValue (next). ReturnIfAbrupt (nextValue).- Append nextValue to the end of the
List values.
- Let nextValue be
- Let next be
- Let len be the number of elements in values.
- Let targetObj be
AllocateTypedArray (C, len). ReturnIfAbrupt (targetObj).- Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kValue be the first element of values and remove that element from values.
- If mapping is
true , then- Let mappedValue be
Call (mapfn, T, «kValue, k»). ReturnIfAbrupt (mappedValue).
- Let mappedValue be
- Else, let mappedValue be kValue.
- Let setStatus be
Set (targetObj, Pk, mappedValue,true ). ReturnIfAbrupt (setStatus).- Increase k by 1.
- Let Pk be
- Assert: values is now an empty
List . - Return targetObj.
- Let iterator be
- Assert: items is not an Iterable so assume it is an array-like object.
- Let arrayLike be
ToObject (items). ReturnIfAbrupt (arrayLike).- Let len be
ToLength (Get (arrayLike,"length")). ReturnIfAbrupt (len).- Let targetObj be
AllocateTypedArray (C, len). ReturnIfAbrupt (targetObj).- Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kValue be
Get (arrayLike, Pk). ReturnIfAbrupt (kValue).- If mapping is
true , then- Let mappedValue be
Call (mapfn, T, «kValue, k»). ReturnIfAbrupt (mappedValue).
- Let mappedValue be
- Else, let mappedValue be kValue.
- Let setStatus be
Set (targetObj, Pk, mappedValue,true ). ReturnIfAbrupt (setStatus).- Increase k by 1.
- Let Pk be
- Return targetObj.
22.2.2.2 %TypedArray% .of ( ...items )
When the of method is called with any number of arguments, the following steps are taken:
- Let len be the actual number of arguments passed to this function.
- Let items be the
List of arguments passed to this function. - Let C be the
this value. - If
IsConstructor (C) isfalse , throw aTypeError exception. - Let newObj be
AllocateTypedArray (C, len). ReturnIfAbrupt (newObj).- Let k be 0.
- Repeat, while k < len
- Let kValue be items[k].
- Let Pk be
ToString (k). - Let status be
Set (newObj, Pk, kValue,true ). ReturnIfAbrupt (status).- Increase k by 1.
- Return newObj.
The length property of the of method is 0.
The items argument is assumed to be a well-formed rest argument value.
22.2.2.3 %TypedArray% .prototype
The initial value of
This property has the attributes { [[Writable]]:
22.2.2.4 get %TypedArray% [ @@species ]
- Return the
this value.
The value of the name property of this function is "get [Symbol.species]".
this object's constructor to create a derived object. However, a subclass constructor may over-ride that default behaviour by redefining its @@species property.
22.2.3 Properties of the %TypedArrayPrototype% Object
The value of the [[Prototype]] internal slot of the
22.2.3.1 get %TypedArray% .prototype.buffer
prototype.buffer is an accessor property whose set accessor function is
- Let O be the
this value. - If
Type (O) is not Object, throw aTypeError exception. - If O does not have a [[ViewedArrayBuffer]] internal slot, throw a
TypeError exception. - Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- Return buffer.
22.2.3.2 get %TypedArray% .prototype.byteLength
prototype.byteLength is an accessor property whose set accessor function is
- Let O be the
this value. - If
Type (O) is not Object, throw aTypeError exception. - If O does not have a [[ViewedArrayBuffer]] internal slot, throw a
TypeError exception. - Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (buffer) istrue , return 0. - Let size be the value of O's [[ByteLength]] internal slot.
- Return size.
22.2.3.3 get %TypedArray% .prototype.byteOffset
prototype.byteOffset is an accessor property whose set accessor function is
- Let O be the
this value. - If
Type (O) is not Object, throw aTypeError exception. - If O does not have a [[ViewedArrayBuffer]] internal slot, throw a
TypeError exception. - Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (buffer) istrue , return 0. - Let offset be the value of O's [[ByteOffset]] internal slot.
- Return offset.
22.2.3.4 %TypedArray% .prototype.constructor
The initial value of
22.2.3.5 %TypedArray% .prototype.copyWithin (target, start [, end ] )
.prototype.copyWithin is a distinct function that implements the same algorithm as Array.prototype.copyWithin as defined in "length" and the actual copying of values in step 17 must be performed in a manner that preserves the bit-level encoding of the source data
The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the copyWithin method is 2.
22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
When called with argument O the following steps are taken:
- If
Type (O) is not Object, throw aTypeError exception. - If O does not have a [[TypedArrayName]] internal slot, throw a
TypeError exception. - If O does not have a [[ViewedArrayBuffer]] internal slot, throw a
TypeError exception. - Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - Return buffer.
22.2.3.6 %TypedArray% .prototype.entries ( )
The following steps are taken:
- Let O be the
this value. - Let valid be
ValidateTypedArray (O). ReturnIfAbrupt (valid).- Return
CreateArrayIterator (O,"key+value").
22.2.3.7 %TypedArray% .prototype.every ( callbackfn [ , thisArg ] )
.prototype.every is a distinct function that implements the same algorithm as Array.prototype.every as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the every method is 1.
22.2.3.8 %TypedArray% .prototype.fill (value [ , start [ , end ] ] )
.prototype.fill is a distinct function that implements the same algorithm as Array.prototype.fill as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the fill method is 1.
22.2.3.9 %TypedArray% .prototype.filter ( callbackfn [ , thisArg ] )
The interpretation and use of the arguments of .prototype.filter are the same as for Array.prototype.filter as defined in
When the filter method is called with one or two arguments, the following steps are taken:
- Let O be the
this value. - Let valid be
ValidateTypedArray (O). ReturnIfAbrupt (valid).- Let len be the value of O's [[ArrayLength]] internal slot.
- If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let defaultConstructor be the intrinsic object listed in column one of
Table 49 for the value of O's [[TypedArrayName]] internal slot. - Let C be
SpeciesConstructor (O, defaultConstructor). ReturnIfAbrupt (C).- Let kept be a new empty
List . - Let k be 0.
- Let captured be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let selected be
ToBoolean (Call (callbackfn, T, «kValue, k, O»)). ReturnIfAbrupt (selected).- If selected is
true , then- Append kValue to the end of kept.
- Increase captured by 1.
- Increase k by 1.
- Let Pk be
- Let A be
AllocateTypedArray (C, captured). ReturnIfAbrupt (A).- Let n be 0.
- For each element e of kept
- Let status be
Set (A,ToString (n), e,true ). ReturnIfAbrupt (status).- Increment n by 1.
- Let status be
- Return A.
This function is not generic. The
The length property of the filter method is 1.
22.2.3.10 %TypedArray% .prototype.find (predicate [ , thisArg ] )
.prototype.find is a distinct function that implements the same algorithm as Array.prototype.find as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the find method is 1.
22.2.3.11 %TypedArray% .prototype.findIndex ( predicate [ , thisArg ] )
.prototype.findIndex is a distinct function that implements the same algorithm as Array.prototype.findIndex as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the findIndex method is 1.
22.2.3.12 %TypedArray% .prototype.forEach ( callbackfn [ , thisArg ] )
.prototype.forEach is a distinct function that implements the same algorithm as Array.prototype.forEach as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the forEach method is 1.
22.2.3.13 %TypedArray% .prototype.indexOf (searchElement [ , fromIndex ] )
.prototype.indexOf is a distinct function that implements the same algorithm as Array.prototype.indexOf as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the indexOf method is 1.
22.2.3.14 %TypedArray% .prototype.join ( separator )
.prototype.join is a distinct function that implements the same algorithm as Array.prototype.join as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
22.2.3.15 %TypedArray% .prototype.keys ( )
The following steps are taken:
- Let O be the
this value. - Let valid be
ValidateTypedArray (O). ReturnIfAbrupt (valid).- Return
CreateArrayIterator (O,"key").
22.2.3.16 %TypedArray% .prototype.lastIndexOf ( searchElement [ , fromIndex ] )
.prototype.lastIndexOf is a distinct function that implements the same algorithm as Array.prototype.lastIndexOf as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the lastIndexOf method is 1.
22.2.3.17 get %TypedArray% .prototype.length
prototype.length is an accessor property whose set accessor function is
- Let O be the
this value. - If
Type (O) is not Object, throw aTypeError exception. - If O does not have a [[TypedArrayName]] internal slot, throw a
TypeError exception. - Assert: O has [[ViewedArrayBuffer]] and [[ArrayLength]] internal slots.
- Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (buffer) istrue , return 0. - Let length be the value of O's [[ArrayLength]] internal slot.
- Return length.
This function is not generic. The
22.2.3.18 %TypedArray% .prototype.map ( callbackfn [ , thisArg ] )
The interpretation and use of the arguments of .prototype.map are the same as for Array.prototype.map as defined in
When the map method is called with one or two arguments, the following steps are taken:
- Let O be the
this value. - Let valid be
ValidateTypedArray (O). ReturnIfAbrupt (valid).- Let len be the value of O's [[ArrayLength]] internal slot.
- If
IsCallable (callbackfn) isfalse , throw aTypeError exception. - If thisArg was supplied, let T be thisArg; else let T be
undefined . - Let defaultConstructor be the intrinsic object listed in column one of
Table 49 for the value of O's [[TypedArrayName]] internal slot. - Let C be
SpeciesConstructor (O, defaultConstructor). ReturnIfAbrupt (C).- Let A be
AllocateTypedArray (C, len). ReturnIfAbrupt (A).- Let k be 0.
- Repeat, while k < len
- Let Pk be
ToString (k). - Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let mappedValue be
Call (callbackfn, T, «kValue, k, O»). ReturnIfAbrupt (mappedValue).- Let status be
Set (A, Pk, mappedValue,true ). ReturnIfAbrupt (status).- Increase k by 1.
- Let Pk be
- Return A.
This function is not generic. The
The length property of the map method is 1.
22.2.3.19 %TypedArray% .prototype.reduce ( callbackfn [ , initialValue ] )
.prototype.reduce is a distinct function that implements the same algorithm as Array.prototype.reduce as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the reduce method is 1.
22.2.3.20 %TypedArray% .prototype.reduceRight ( callbackfn [ , initialValue ] )
.prototype.reduceRight is a distinct function that implements the same algorithm as Array.prototype.reduceRight as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the reduceRight method is 1.
22.2.3.21 %TypedArray% .prototype.reverse ( )
.prototype.reverse is a distinct function that implements the same algorithm as Array.prototype.reverse as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
22.2.3.22 %TypedArray% .prototype.set ( overloaded [ , offset ])
.prototype.set is a single function whose behaviour is overloaded based upon the type of its first argument.
This function is not generic. The
The length property of the set method is 1.
22.2.3.22.1 %TypedArray% .prototype.set (array [ , offset ] )
Sets multiple values in this TypedArray, reading the values from the object array. The optional offset value indicates the first element index in this TypedArray where values are written. If omitted, it is assumed to be 0.
- Assert: array is any
ECMAScript language value other than an Object with a [[TypedArrayName]] internal slot. If it is such an Object, the definition in22.2.3.22.2 applies. - Let target be the
this value. - If
Type (target) is not Object, throw aTypeError exception. - If target does not have a [[TypedArrayName]] internal slot, throw a
TypeError exception. - Assert: target has a [[ViewedArrayBuffer]] internal slot.
- Let targetOffset be
ToInteger (offset). ReturnIfAbrupt (targetOffset).- If targetOffset < 0, throw a
RangeError exception. - Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (targetBuffer) istrue , throw aTypeError exception. - Let targetLength be the value of target's [[ArrayLength]] internal slot.
- Let targetName be the String value of target's [[TypedArrayName]] internal slot.
- Let targetElementSize be the Number value of the Element Size value specified in
Table 49 for targetName. - Let targetType be the String value of the Element Type value in
Table 49 for targetName. - Let targetByteOffset be the value of target's [[ByteOffset]] internal slot.
- Let src be
ToObject (array). ReturnIfAbrupt (src).- Let srcLength be
ToLength (Get (src,"length")). ReturnIfAbrupt (srcLength).- If srcLength + targetOffset > targetLength, throw a
RangeError exception. - Let targetByteIndex be targetOffset × targetElementSize + targetByteOffset.
- Let k be 0.
- Let limit be targetByteIndex + targetElementSize × srcLength.
- Repeat, while targetByteIndex < limit
- Let Pk be
ToString (k). - Let kNumber be
ToNumber (Get (src, Pk)). ReturnIfAbrupt (kNumber).- If
IsDetachedBuffer (targetBuffer) istrue , throw aTypeError exception. - Perform
SetValueInBuffer (targetBuffer, targetByteIndex, targetType, kNumber). - Set k to k + 1.
- Set targetByteIndex to targetByteIndex + targetElementSize.
- Let Pk be
- Return
undefined .
22.2.3.22.2 %TypedArray% .prototype.set(typedArray [, offset ] )
Sets multiple values in this TypedArray, reading the values from the typedArray argument object. The optional offset value indicates the first element index in this TypedArray where values are written. If omitted, it is assumed to be 0.
- Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, the definition in
22.2.3.22.1 applies. - Let target be the
this value. - If
Type (target) is not Object, throw aTypeError exception. - If target does not have a [[TypedArrayName]] internal slot, throw a
TypeError exception. - Assert: target has a [[ViewedArrayBuffer]] internal slot.
- Let targetOffset be
ToInteger (offset). ReturnIfAbrupt (targetOffset).- If targetOffset < 0, throw a
RangeError exception. - Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (targetBuffer) istrue , throw aTypeError exception. - Let targetLength be the value of target's [[ArrayLength]] internal slot.
- Let srcBuffer be the value of typedArray's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (srcBuffer) istrue , throw aTypeError exception. - Let targetName be the String value of target's [[TypedArrayName]] internal slot.
- Let targetType be the String value of the Element Type value in
Table 49 for targetName. - Let targetElementSize be the Number value of the Element Size value specified in
Table 49 for targetName. - Let targetByteOffset be the value of target's [[ByteOffset]] internal slot.
- Let srcName be the String value of typedArray's [[TypedArrayName]] internal slot.
- Let srcType be the String value of the Element Type value in
Table 49 for srcName . - Let srcElementSize be the Number value of the Element Size value specified in
Table 49 for srcName. - Let srcLength be the value of typedArray's [[ArrayLength]] internal slot.
- Let srcByteOffset be the value of typedArray's [[ByteOffset]] internal slot.
- If srcLength + targetOffset > targetLength, throw a
RangeError exception. - If
SameValue (srcBuffer, targetBuffer) istrue , then- Let srcBuffer be
CloneArrayBuffer (targetBuffer, srcByteOffset,%ArrayBuffer% ). - NOTE:
%ArrayBuffer% is used to clone targetBuffer because is it known to not have any observable side-effects. ReturnIfAbrupt (srcBuffer).- Let srcByteIndex be 0.
- Let srcBuffer be
- Else, let srcByteIndex be srcByteOffset.
- Let targetByteIndex be targetOffset × targetElementSize + targetByteOffset.
- Let limit be targetByteIndex + targetElementSize × srcLength.
- If
SameValue (srcType, targetType) isfalse , then- Repeat, while targetByteIndex < limit
- Let value be
GetValueFromBuffer (srcBuffer, srcByteIndex, srcType). - Perform
SetValueInBuffer (targetBuffer, targetByteIndex, targetType, value). - Set srcByteIndex to srcByteIndex + srcElementSize.
- Set targetByteIndex to targetByteIndex + targetElementSize.
- Let value be
- Repeat, while targetByteIndex < limit
- Else,
- NOTE: If srcType and targetType are the same the transfer must be performed in a manner that preserves the bit-level encoding of the source data.
- Repeat, while targetByteIndex < limit
- Let value be
GetValueFromBuffer (srcBuffer, srcByteIndex,"Uint8"). - Perform
SetValueInBuffer (targetBuffer, targetByteIndex,"Uint8", value). - Set srcByteIndex to srcByteIndex + 1.
- Set targetByteIndex to targetByteIndex + 1.
- Let value be
- Return
undefined .
22.2.3.23 %TypedArray% .prototype.slice ( start, end )
The interpretation and use of the arguments of .prototype.slice are the same as for Array.prototype.slice as defined in
- Let O be the
this value. - Let valid be
ValidateTypedArray (O). ReturnIfAbrupt (valid).- Let len be the value of O's [[ArrayLength]] internal slot.
- Let relativeStart be
ToInteger (start). ReturnIfAbrupt (relativeStart).- 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 beToInteger (end). ReturnIfAbrupt (relativeEnd).- 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 defaultConstructor be the intrinsic object listed in column one of
Table 49 for the value of O's [[TypedArrayName]] internal slot. - Let C be
SpeciesConstructor (O, defaultConstructor). ReturnIfAbrupt (C).- Let A be
AllocateTypedArray (C, count). ReturnIfAbrupt (A).- Let srcName be the String value of O's [[TypedArrayName]] internal slot.
- Let srcType be the String value of the Element Type value in
Table 49 for srcName. - Let targetName be the String value of A's [[TypedArrayName]] internal slot.
- Let targetType be the String value of the Element Type value in
Table 49 for targetName. - If
SameValue (srcType, targetType) isfalse , then- Let n be 0.
- Repeat, while k < final
- Let Pk be
ToString (k). - Let kValue be
Get (O, Pk). ReturnIfAbrupt (kValue).- Let status be
Set (A,ToString (n), kValue,true ). ReturnIfAbrupt (status).- Increase k by 1.
- Increase n by 1.
- Let Pk be
- Else if count > 0,
- Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- If
IsDetachedBuffer (srcBuffer) istrue , throw aTypeError exception. - Let targetBuffer be the value of A's [[ViewedArrayBuffer]] internal slot.
- Let elementSize be the Number value of the Element Size value specified in
Table 49 for srcType. - NOTE: If srcType and targetType are the same the transfer must be performed in a manner that preserves the bit-level encoding of the source data.
- Let srcByteOffet be the value of O's [[ByteOffset]] internal slot.
- Let targetByteIndex be 0.
- Let srcByteIndex be (k × elementSize) + srcByteOffet.
- Repeat, while targetByteIndex < count × elementSize
- Let value be
GetValueFromBuffer (srcBuffer, srcByteIndex,"Uint8"). - Perform
SetValueInBuffer (targetBuffer, targetByteIndex,"Uint8", value). - Increase srcByteIndex by 1.
- Increase targetByteIndex by 1.
- Let value be
- Return A.
This function is not generic. The
The length property of the slice method is 2.
22.2.3.24 %TypedArray% .prototype.some ( callbackfn [ , thisArg ] )
.prototype.some is a distinct function that implements the same algorithm as Array.prototype.some as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
The length property of the some method is 1.
22.2.3.25 %TypedArray% .prototype.sort ( comparefn )
.prototype.sort is a distinct function that, except as described below, implements the same requirements as those of Array.prototype.sort as defined in .prototype.sort specification may be optimized with the knowledge that the
This function is not generic. The
Upon entry, the following steps are performed to initialize evaluation of the sort function. These steps are used instead of the entry steps in
- Let obj be the
this value as the argument. - Let buffer be
ValidateTypedArray (obj). ReturnIfAbrupt (buffer).- Let len be the value of obj's [[ArrayLength]] internal slot.
The implementation defined sort order condition for exotic objects is not applied by .prototype.sort.
The following version of .prototype.sort. It performs a numeric comparison rather than the string comparison used in sort method.
When the TypedArray
- Assert: Both
Type (x) andType (y) is Number. - If the argument comparefn is not
undefined , then- Let v be
Call (comparefn,undefined , «x, y»). ReturnIfAbrupt (v).- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - If v is
NaN , return +0. - Return v.
- Let v be
- If x and y are both
NaN , return +0. - If x is
NaN , return 1. - If y is
NaN , return -1. - If x < y, return -1.
- If x > y, return 1.
- If x is -0 and y is +0, return -1.
- If x is +0 and y is -0, return 1.
- Return +0.
Because
22.2.3.26 %TypedArray% .prototype.subarray( [ begin [ , end ] ] )
Returns a new TypedArray object whose element type is the same as this TypedArray and whose ArrayBuffer is the same as the ArrayBuffer of this TypedArray, referencing the elements at begin, inclusive, up to end, exclusive. If either begin or end is negative, it refers to an index from the end of the array, as opposed to from the beginning.
- Let O be the
this value. - If
Type (O) is not Object, throw aTypeError exception. - If O does not have a [[TypedArrayName]] internal slot, throw a
TypeError exception. - Assert: O has a [[ViewedArrayBuffer]] internal slot.
- Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
- Let srcLength be the value of O's [[ArrayLength]] internal slot.
- Let relativeBegin be
ToInteger (begin). ReturnIfAbrupt (relativeBegin).- If relativeBegin < 0, let beginIndex be max((srcLength + relativeBegin), 0); else let beginIndex be min(relativeBegin, srcLength).
- If end is
undefined , let relativeEnd be srcLength; else, let relativeEnd beToInteger (end). ReturnIfAbrupt (relativeEnd).- If relativeEnd < 0, let endIndex be max((srcLength + relativeEnd), 0); else let endIndex be min(relativeEnd, srcLength).
- Let newLength be max(endIndex - beginIndex, 0).
- Let constructorName be the String value of O's [[TypedArrayName]] internal slot.
- Let elementSize be the Number value of the Element Size value specified in
Table 49 for constructorName. - Let srcByteOffset be the value of O's [[ByteOffset]] internal slot.
- Let beginByteOffset be srcByteOffset + beginIndex × elementSize.
- Let defaultConstructor be the intrinsic object listed in column one of
Table 49 for constructorName. - Let constructor be
SpeciesConstructor (O, defaultConstructor). ReturnIfAbrupt (constructor).- Let argumentsList be «buffer, beginByteOffset, newLength».
- Return
Construct (constructor, argumentsList).
This function is not generic. The
The length property of the subarray method is 2.
22.2.3.27 %TypedArray% .prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
.prototype.toLocaleString is a distinct function that implements the same algorithm as Array.prototype.toLocaleString as defined in "length". The implementation of the algorithm may be optimized with the knowledge that the
This function is not generic.
If the ECMAScript implementation includes the ECMA-402 Internationalization API this function is based upon the algorithm for Array.prototype.toLocaleString that is in the ECMA-402 specification.
22.2.3.28 %TypedArray% .prototype.toString ( )
The initial value of the .prototype.toString data property is the same built-in function object as the Array.prototype.toString method defined in
22.2.3.29 %TypedArray% .prototype.values ( )
The following steps are taken:
- Let O be the
this value. - Let valid be
ValidateTypedArray (O). ReturnIfAbrupt (valid).- Return
CreateArrayIterator (O,"value").
22.2.3.30 %TypedArray% .prototype [ @@iterator ] ( )
The initial value of the @@iterator property is the same function object as the initial value of the .prototype.values property.
22.2.3.31 get %TypedArray% .prototype [ @@toStringTag ]
prototype[@@toStringTag] is an accessor property whose set accessor function is
- Let O be the
this value. - If
Type (O) is not Object, returnundefined . - If O does not have a [[TypedArrayName]] internal slot, return
undefined . - Let name be the value of O's [[TypedArrayName]] internal slot.
- Assert: name is a String value.
- Return name.
This property has the attributes { [[Enumerable]]:
The initial value of the name property of this function is "get [Symbol.toStringTag]".
22.2.4 The TypedArray Constructors
Each of the TypedArray constructor objects is an intrinsic object that has the structure described below, differing only in the name used as the constructor name instead of TypedArray, in
The TypedArray constructors are not intended to be called as a function and will throw an exception when called in that manner.
The TypedArray constructors are designed to be subclassable. They may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified TypedArray behaviour must include a super call to the TypedArray constructor to create and initialize the subclass instance with the internal state necessary to support the %TypedArray%.prototype built-in methods.
22.2.4.1 TypedArray( ... argumentsList)
A TypedArray constructor with a list of arguments argumentsList performs the following steps:
- If NewTarget is
undefined , throw aTypeError exception. - Let here be the active function.
- Let super be here.[[GetPrototypeOf]]().
ReturnIfAbrupt (super).- If
IsConstructor (super) isfalse , throw aTypeError exception. - Let argumentsList be the argumentsList argument of the [[Construct]] internal method that invoked the active function.
- Return
Construct (super, argumentsList, NewTarget).
22.2.5 Properties of the TypedArray Constructors
The value of the [[Prototype]] internal slot of each TypedArray constructor is the
Each TypedArray constructor has a [[TypedArrayConstructorName]] internal slot property whose value is the String value of the constructor name specified for it in
Each TypedArray constructor has a name property whose value is the String value of the constructor name specified for it in
Besides a length property (whose value is 3), each TypedArray constructor has the following properties:
22.2.5.1 TypedArray.BYTES_PER_ELEMENT
The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the Element Size value specified in
This property has the attributes { [[Writable]]:
22.2.5.2 TypedArray.prototype
The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (
This property has the attributes { [[Writable]]:
22.2.6 Properties of TypedArray Prototype Objects
The value of the [[Prototype]] internal slot of a TypedArray prototype object is the intrinsic object
22.2.6.1 TypedArray.prototype.BYTES_PER_ELEMENT
The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value of the Element Size value specified in
This property has the attributes { [[Writable]]:
22.2.6.2 TypedArray.prototype.constructor
The initial value of a TypedArray.prototype.constructor is the corresponding %TypedArray% intrinsic object.
22.2.7 Properties of TypedArray Instances
TypedArray instances are Integer Indexed exotic objects. Each TypedArray instance inherits properties from the corresponding TypedArray prototype object. Each TypedArray instance has the following internal slots: [[TypedArrayName]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]], and [[ArrayLength]].