Files
ask262/spec-built/multipage/indexed-collections.html
T

1597 lines
475 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html><html lang="en-GB-oxendict"><head><meta name="viewport" content="width=device-width, initial-scale=1"><meta charset="utf-8"><meta property="og:image" content="https://tc39.es/ecmarkup/ecma-logo.png"><meta property="og:title" content="ECMAScript® 2026 Language&nbsp;Specification"><meta property="og:description" content="Introduction
This Ecma Standard defines the ECMAScript 2026 Language. It is the seventeenth edition of the ECMAScript Language Specification. ECMAScript is based on several originating technologies, the most well-known being JavaScript (Netscape) and JScript (Microsoft). The language was invent">
<link rel="icon" href="../img/favicon.ico">
<link rel="stylesheet" href="../assets/css/ecmarkup.css"><link rel="stylesheet" href="../assets/css/print.css" media="print">
<title>ECMAScript® 2026 Language&nbsp;Specification</title><script src="../assets/js/multipage.js?cache=Wu2V1pj2" defer=""></script><script src="../assets/js/ecmarkup.js?cache=BPFBckdu" defer=""></script><link rel="canonical" href="../#sec-indexed-collections"></head>
<body><div id="spec-container"><emu-clause id="sec-indexed-collections">
<h1><span class="secnum">23</span> Indexed Collections</h1>
<emu-clause id="sec-array-objects">
<h1><span class="secnum">23.1</span> Array Objects</h1>
<p>Arrays are <emu-xref href="#exotic-object" id="_ref_12638"><a href="ecmascript-data-types-and-values.html#exotic-object">exotic objects</a></emu-xref> that give special treatment to a certain class of <emu-xref href="#property-name" id="_ref_12639"><a href="ecmascript-data-types-and-values.html#property-name">property names</a></emu-xref>. See <emu-xref href="#sec-array-exotic-objects" id="_ref_717"><a href="ordinary-and-exotic-objects-behaviours.html#sec-array-exotic-objects">10.4.2</a></emu-xref> for a definition of this special treatment.</p>
<emu-clause id="sec-array-constructor">
<h1><span class="secnum">23.1.1</span> The Array Constructor</h1>
<p>The Array <emu-xref href="#constructor" id="_ref_12640"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
<ul>
<li>is <dfn tabindex="-1">%Array%</dfn>.</li>
<li>is the initial value of the <emu-val>"Array"</emu-val> property of the <emu-xref href="#sec-global-object" id="_ref_12641"><a href="global-object.html#sec-global-object">global object</a></emu-xref>.</li>
<li>creates and initializes a new Array when called as a <emu-xref href="#constructor" id="_ref_12642"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>.</li>
<li>also creates and initializes a new Array when called as a function rather than as a <emu-xref href="#constructor" id="_ref_12643"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>. Thus the function call <code>Array(…)</code> is equivalent to the object creation expression <code>new Array(…)</code> with the same arguments.</li>
<li>is a function whose behaviour differs based upon the number and types of its arguments.</li>
<li>may be used as the value of an <code>extends</code> clause of a class definition. Subclass <emu-xref href="#constructor" id="_ref_12644"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that intend to inherit the exotic Array behaviour must include a <code>super</code> call to the Array <emu-xref href="#constructor" id="_ref_12645"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to initialize subclass instances that are <emu-xref href="#array-exotic-object" id="_ref_12646"><a href="ordinary-and-exotic-objects-behaviours.html#array-exotic-object">Array exotic objects</a></emu-xref>. However, most of the <code>Array.prototype</code> methods are generic methods that are not dependent upon their <emu-val>this</emu-val> value being an <emu-xref href="#array-exotic-object" id="_ref_12647"><a href="ordinary-and-exotic-objects-behaviours.html#array-exotic-object">Array exotic object</a></emu-xref>.</li>
</ul>
<emu-clause id="sec-array" oldids="sec-array-constructor-array,sec-array-len,sec-array-items" type="built-in function"><span id="sec-array-items"></span><span id="sec-array-len"></span><span id="sec-array-constructor-array"></span>
<h1><span class="secnum">23.1.1.1</span> Array ( ...<var>values</var> )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg><ol><li>If NewTarget is <emu-val>undefined</emu-val>, let <var>newTarget</var> be the <emu-xref href="#active-function-object" id="_ref_12648"><a href="executable-code-and-execution-contexts.html#active-function-object">active function object</a></emu-xref>; else let <var>newTarget</var> be NewTarget.</li><li>Let <var>proto</var> be ?&nbsp;<emu-xref aoid="GetPrototypeFromConstructor" id="_ref_12649"><a href="ordinary-and-exotic-objects-behaviours.html#sec-getprototypefromconstructor" class="e-user-code">GetPrototypeFromConstructor</a></emu-xref>(<var>newTarget</var>, <emu-val>"%Array.prototype%"</emu-val>).</li><li>Let <var>numberOfArgs</var> be the number of elements in <var>values</var>.</li><li>If <var>numberOfArgs</var> = 0, return !&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_12650"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(0, <var>proto</var>).</li><li>If <var>numberOfArgs</var> = 1, then<ol><li>Let <var>len</var> be <var>values</var>[0].</li><li>Let <var>array</var> be !&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_12651"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(0, <var>proto</var>).</li><li>If <var>len</var> <emu-xref href="#sec-ecmascript-language-types-number-type" id="_ref_12652"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-number-type">is not a Number</a></emu-xref>, then<ol><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12653"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>array</var>, <emu-val>"0"</emu-val>, <var>len</var>).</li><li>Let <var>intLen</var> be <emu-val>1</emu-val><sub>𝔽</sub>.</li></ol></li><li>Else,<ol><li>Let <var>intLen</var> be !&nbsp;<emu-xref aoid="ToUint32" id="_ref_12654"><a href="abstract-operations.html#sec-touint32">ToUint32</a></emu-xref>(<var>len</var>).</li><li>If <emu-xref aoid="SameValueZero" id="_ref_12655"><a href="abstract-operations.html#sec-samevaluezero">SameValueZero</a></emu-xref>(<var>intLen</var>, <var>len</var>) is <emu-val>false</emu-val>, throw a <emu-val>RangeError</emu-val> exception.</li></ol></li><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_12656"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>array</var>, <emu-val>"length"</emu-val>, <var>intLen</var>, <emu-val>true</emu-val>).</li><li>Return <var>array</var>.</li></ol></li><li><emu-xref href="#assert" id="_ref_12657"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>numberOfArgs</var> ≥ 2.</li><li>Let <var>array</var> be ?&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_12658"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(<var>numberOfArgs</var>, <var>proto</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>numberOfArgs</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12659"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12660"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>itemK</var> be <var>values</var>[<var>k</var>].</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12661"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>array</var>, <var>Pk</var>, <var>itemK</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li><emu-xref href="#assert" id="_ref_12662"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: The <emu-xref href="#mathematical-value-of" id="_ref_12663"><a href="notational-conventions.html#mathematical-value-of">mathematical value of</a></emu-xref> <var>array</var>'s <emu-val>"length"</emu-val> property is <var>numberOfArgs</var>.</li><li>Return <var>array</var>.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-array-constructor">
<h1><span class="secnum">23.1.2</span> Properties of the Array Constructor</h1>
<p>The Array <emu-xref href="#constructor" id="_ref_12664"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
<ul>
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-function-prototype-object" id="_ref_12665"><a href="fundamental-objects.html#sec-properties-of-the-function-prototype-object">%Function.prototype%</a></emu-xref>.</li>
<li>has a <emu-val>"length"</emu-val> property whose value is <emu-val>1</emu-val><sub>𝔽</sub>.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-array.from" type="built-in function">
<h1><span class="secnum">23.1.2.1</span> Array.from ( <var>items</var> [ , <var>mapper</var> [ , <var>thisArg</var> ] ] )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>C</var> be the <emu-val>this</emu-val> value.</li><li>If <var>mapper</var> is <emu-val>undefined</emu-val>, then<ol><li>Let <var>mapping</var> be <emu-val>false</emu-val>.</li></ol></li><li>Else,<ol><li>If <emu-xref aoid="IsCallable" id="_ref_12666"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>mapper</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>mapping</var> be <emu-val>true</emu-val>.</li></ol></li><li>Let <var>usingIterator</var> be ?&nbsp;<emu-xref aoid="GetMethod" id="_ref_12667"><a href="abstract-operations.html#sec-getmethod" class="e-user-code">GetMethod</a></emu-xref>(<var>items</var>, <emu-xref href="#sec-well-known-symbols" id="_ref_12668"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref>).</li><li>If <var>usingIterator</var> is not <emu-val>undefined</emu-val>, then<ol><li>If <emu-xref aoid="IsConstructor" id="_ref_12669"><a href="abstract-operations.html#sec-isconstructor">IsConstructor</a></emu-xref>(<var>C</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="Construct" id="_ref_12670"><a href="abstract-operations.html#sec-construct" class="e-user-code">Construct</a></emu-xref>(<var>C</var>).</li></ol></li><li>Else,<ol><li>Let <var>A</var> be !&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_12671"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(0).</li></ol></li><li>Let <var>iteratorRecord</var> be ?&nbsp;<emu-xref aoid="GetIteratorFromMethod" id="_ref_12672"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>items</var>, <var>usingIterator</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat,<ol><li>If <var>k</var> ≥ 2<sup>53</sup> - 1, then<ol><li>Let <var>error</var> be <emu-xref aoid="ThrowCompletion" id="_ref_12673"><a href="ecmascript-data-types-and-values.html#sec-throwcompletion">ThrowCompletion</a></emu-xref>(a newly created <emu-val>TypeError</emu-val> object).</li><li>Return ?&nbsp;<emu-xref aoid="IteratorClose" id="_ref_12674"><a href="abstract-operations.html#sec-iteratorclose" class="e-user-code">IteratorClose</a></emu-xref>(<var>iteratorRecord</var>, <var>error</var>).</li></ol></li><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12675"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12676"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>next</var> be ?&nbsp;<emu-xref aoid="IteratorStepValue" id="_ref_12677"><a href="abstract-operations.html#sec-iteratorstepvalue" class="e-user-code">IteratorStepValue</a></emu-xref>(<var>iteratorRecord</var>).</li><li>If <var>next</var> is <emu-const>done</emu-const>, then<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_12678"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_12679"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <emu-val>true</emu-val>).</li><li>Return <var>A</var>.</li></ol></li><li>If <var>mapping</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>mappedValue</var> be <emu-xref aoid="Completion" id="_ref_12680"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="Call" id="_ref_12681"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>mapper</var>, <var>thisArg</var>, « <var>next</var>, <emu-xref aoid="𝔽" id="_ref_12682"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)&nbsp;»)).</li><li><emu-xref aoid="IfAbruptCloseIterator" id="_ref_12683"><a href="abstract-operations.html#sec-ifabruptcloseiterator" class="e-user-code">IfAbruptCloseIterator</a></emu-xref>(<var>mappedValue</var>, <var>iteratorRecord</var>).</li></ol></li><li>Else,<ol><li>Let <var>mappedValue</var> be <var>next</var>.</li></ol></li><li>Let <var>defineStatus</var> be <emu-xref aoid="Completion" id="_ref_12684"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12685"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>mappedValue</var>)).</li><li><emu-xref aoid="IfAbruptCloseIterator" id="_ref_12686"><a href="abstract-operations.html#sec-ifabruptcloseiterator" class="e-user-code">IfAbruptCloseIterator</a></emu-xref>(<var>defineStatus</var>, <var>iteratorRecord</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li></ol></li><li>NOTE: <var>items</var> is not <emu-xref href="#sec-iterable-interface" id="_ref_12687"><a href="control-abstraction-objects.html#sec-iterable-interface">iterable</a></emu-xref> so assume it is an <emu-xref href="#sec-lengthofarraylike" id="_ref_12688"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref>.</li><li>Let <var>arrayLike</var> be !&nbsp;<emu-xref aoid="ToObject" id="_ref_12689"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<var>items</var>).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12690"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>arrayLike</var>).</li><li>If <emu-xref aoid="IsConstructor" id="_ref_12691"><a href="abstract-operations.html#sec-isconstructor">IsConstructor</a></emu-xref>(<var>C</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="Construct" id="_ref_12692"><a href="abstract-operations.html#sec-construct" class="e-user-code">Construct</a></emu-xref>(<var>C</var>, « <emu-xref aoid="𝔽" id="_ref_12693"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>)&nbsp;»).</li></ol></li><li>Else,<ol><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_12694"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(<var>len</var>).</li></ol></li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12695"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12696"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12697"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>arrayLike</var>, <var>Pk</var>).</li><li>If <var>mapping</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>mappedValue</var> be ?&nbsp;<emu-xref aoid="Call" id="_ref_12698"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>mapper</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_12699"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)&nbsp;»).</li></ol></li><li>Else,<ol><li>Let <var>mappedValue</var> be <var>kValue</var>.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12700"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>mappedValue</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_12701"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_12702"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>), <emu-val>true</emu-val>).</li><li>Return <var>A</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>This method is an intentionally generic factory method; it does not require that its <emu-val>this</emu-val> value be the Array <emu-xref href="#constructor" id="_ref_12703"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>. Therefore it can be transferred to or inherited by any other <emu-xref href="#constructor" id="_ref_12704"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that may be called with a single numeric argument.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.fromasync" type="built-in function">
<h1><span class="secnum">23.1.2.2</span> Array.fromAsync ( <var>items</var> [ , <var>mapper</var> [ , <var>thisArg</var> ] ] )</h1>
<p>This async function performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>C</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>mapping</var> be <emu-val>false</emu-val>.</li><li>If <var>mapper</var> is not <emu-val>undefined</emu-val>, then<ol><li>If <emu-xref aoid="IsCallable" id="_ref_12705"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>mapper</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Set <var>mapping</var> to <emu-val>true</emu-val>.</li></ol></li><li>Let <var>iteratorRecord</var> be <emu-val>undefined</emu-val>.</li><li>Let <var>usingAsyncIterator</var> be ?&nbsp;<emu-xref aoid="GetMethod" id="_ref_12706"><a href="abstract-operations.html#sec-getmethod" class="e-user-code">GetMethod</a></emu-xref>(<var>items</var>, <emu-xref href="#sec-well-known-symbols" id="_ref_12707"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.asyncIterator%</a></emu-xref>).</li><li>If <var>usingAsyncIterator</var> is <emu-val>undefined</emu-val>, then<ol><li>Let <var>usingSyncIterator</var> be ?&nbsp;<emu-xref aoid="GetMethod" id="_ref_12708"><a href="abstract-operations.html#sec-getmethod" class="e-user-code">GetMethod</a></emu-xref>(<var>items</var>, <emu-xref href="#sec-well-known-symbols" id="_ref_12709"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref>).</li><li>If <var>usingSyncIterator</var> is not <emu-val>undefined</emu-val>, then<ol><li>Set <var>iteratorRecord</var> to <emu-xref aoid="CreateAsyncFromSyncIterator" id="_ref_12710"><a href="control-abstraction-objects.html#sec-createasyncfromsynciterator">CreateAsyncFromSyncIterator</a></emu-xref>(? <emu-xref aoid="GetIteratorFromMethod" id="_ref_12711"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>items</var>, <var>usingSyncIterator</var>)).</li></ol></li></ol></li><li>Else,<ol><li>Set <var>iteratorRecord</var> to ?&nbsp;<emu-xref aoid="GetIteratorFromMethod" id="_ref_12712"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>items</var>, <var>usingAsyncIterator</var>).</li></ol></li><li>If <var>iteratorRecord</var> is not <emu-val>undefined</emu-val>, then<ol><li>If <emu-xref aoid="IsConstructor" id="_ref_12713"><a href="abstract-operations.html#sec-isconstructor">IsConstructor</a></emu-xref>(<var>C</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="Construct" id="_ref_12714"><a href="abstract-operations.html#sec-construct" class="e-user-code">Construct</a></emu-xref>(<var>C</var>).</li></ol></li><li>Else,<ol><li>Let <var>A</var> be !&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_12715"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(0).</li></ol></li><li>Let <var>k</var> be 0.</li><li>Repeat,<ol><li>If <var>k</var> ≥ 2<sup>53</sup> - 1, then<ol><li>Let <var>error</var> be <emu-xref aoid="ThrowCompletion" id="_ref_12716"><a href="ecmascript-data-types-and-values.html#sec-throwcompletion">ThrowCompletion</a></emu-xref>(a newly created <emu-val>TypeError</emu-val> object).</li><li>Return ?&nbsp;<emu-xref aoid="AsyncIteratorClose" id="_ref_12717"><a href="abstract-operations.html#sec-asynciteratorclose" class="e-user-code">AsyncIteratorClose</a></emu-xref>(<var>iteratorRecord</var>, <var>error</var>).</li></ol></li><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12718"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12719"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>nextResult</var> be ?&nbsp;<emu-xref aoid="Call" id="_ref_12720"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>iteratorRecord</var>.<var class="field">[[NextMethod]]</var>, <var>iteratorRecord</var>.<var class="field">[[Iterator]]</var>).</li><li>Set <var>nextResult</var> to ?&nbsp;<emu-xref aoid="Await" id="_ref_12721"><a href="control-abstraction-objects.html#await" class="e-user-code">Await</a></emu-xref>(<var>nextResult</var>).</li><li>If <var>nextResult</var> <emu-xref href="#sec-object-type" id="_ref_12722"><a href="ecmascript-data-types-and-values.html#sec-object-type">is not an Object</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>done</var> be ?&nbsp;<emu-xref aoid="IteratorComplete" id="_ref_12723"><a href="abstract-operations.html#sec-iteratorcomplete" class="e-user-code">IteratorComplete</a></emu-xref>(<var>nextResult</var>).</li><li>If <var>done</var> is <emu-val>true</emu-val>, then<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_12724"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_12725"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <emu-val>true</emu-val>).</li><li>Return <var>A</var>.</li></ol></li><li>Let <var>nextValue</var> be ?&nbsp;<emu-xref aoid="IteratorValue" id="_ref_12726"><a href="abstract-operations.html#sec-iteratorvalue" class="e-user-code">IteratorValue</a></emu-xref>(<var>nextResult</var>).</li><li>If <var>mapping</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>mappedValue</var> be <emu-xref aoid="Completion" id="_ref_12727"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="Call" id="_ref_12728"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>mapper</var>, <var>thisArg</var>, « <var>nextValue</var>, <emu-xref aoid="𝔽" id="_ref_12729"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)&nbsp;»)).</li><li><emu-xref aoid="IfAbruptCloseAsyncIterator" id="_ref_12730"><a href="abstract-operations.html#sec-ifabruptcloseasynciterator" class="e-user-code">IfAbruptCloseAsyncIterator</a></emu-xref>(<var>mappedValue</var>, <var>iteratorRecord</var>).</li><li>Set <var>mappedValue</var> to <emu-xref aoid="Completion" id="_ref_12731"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="Await" id="_ref_12732"><a href="control-abstraction-objects.html#await" class="e-user-code">Await</a></emu-xref>(<var>mappedValue</var>)).</li><li><emu-xref aoid="IfAbruptCloseAsyncIterator" id="_ref_12733"><a href="abstract-operations.html#sec-ifabruptcloseasynciterator" class="e-user-code">IfAbruptCloseAsyncIterator</a></emu-xref>(<var>mappedValue</var>, <var>iteratorRecord</var>).</li></ol></li><li>Else,<ol><li>Let <var>mappedValue</var> be <var>nextValue</var>.</li></ol></li><li>Let <var>defineStatus</var> be <emu-xref aoid="Completion" id="_ref_12734"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12735"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>mappedValue</var>)).</li><li><emu-xref aoid="IfAbruptCloseAsyncIterator" id="_ref_12736"><a href="abstract-operations.html#sec-ifabruptcloseasynciterator" class="e-user-code">IfAbruptCloseAsyncIterator</a></emu-xref>(<var>defineStatus</var>, <var>iteratorRecord</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li></ol></li><li>Else,<ol><li>NOTE: <var>items</var> is neither <emu-xref href="#sec-asynciterable-interface" id="_ref_12737"><a href="control-abstraction-objects.html#sec-asynciterable-interface">async iterable</a></emu-xref> nor <emu-xref href="#sec-iterable-interface" id="_ref_12738"><a href="control-abstraction-objects.html#sec-iterable-interface">iterable</a></emu-xref> so assume it is an <emu-xref href="#sec-lengthofarraylike" id="_ref_12739"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref>.</li><li>Let <var>arrayLike</var> be !&nbsp;<emu-xref aoid="ToObject" id="_ref_12740"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<var>items</var>).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12741"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>arrayLike</var>).</li><li>If <emu-xref aoid="IsConstructor" id="_ref_12742"><a href="abstract-operations.html#sec-isconstructor">IsConstructor</a></emu-xref>(<var>C</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="Construct" id="_ref_12743"><a href="abstract-operations.html#sec-construct" class="e-user-code">Construct</a></emu-xref>(<var>C</var>, « <emu-xref aoid="𝔽" id="_ref_12744"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>)&nbsp;»).</li></ol></li><li>Else,<ol><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_12745"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(<var>len</var>).</li></ol></li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12746"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12747"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12748"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>arrayLike</var>, <var>Pk</var>).</li><li>Set <var>kValue</var> to ?&nbsp;<emu-xref aoid="Await" id="_ref_12749"><a href="control-abstraction-objects.html#await" class="e-user-code">Await</a></emu-xref>(<var>kValue</var>).</li><li>If <var>mapping</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>mappedValue</var> be ?&nbsp;<emu-xref aoid="Call" id="_ref_12750"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>mapper</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_12751"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)&nbsp;»).</li><li>Set <var>mappedValue</var> to ?&nbsp;<emu-xref aoid="Await" id="_ref_12752"><a href="control-abstraction-objects.html#await" class="e-user-code">Await</a></emu-xref>(<var>mappedValue</var>).</li></ol></li><li>Else,<ol><li>Let <var>mappedValue</var> be <var>kValue</var>.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12753"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>mappedValue</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_12754"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_12755"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>), <emu-val>true</emu-val>).</li><li>Return <var>A</var>.</li></ol></li></ol></emu-alg>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>This method is an intentionally generic factory method; it does not require that its <emu-val>this</emu-val> value be the Array <emu-xref href="#constructor" id="_ref_12756"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>. Therefore it can be transferred to or inherited by any other <emu-xref href="#constructor" id="_ref_12757"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that may be called with a single numeric argument.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.isarray" type="built-in function">
<h1><span class="secnum">23.1.2.3</span> Array.isArray ( <var>arg</var> )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg><ol><li>Return ?&nbsp;<emu-xref aoid="IsArray" id="_ref_12758"><a href="abstract-operations.html#sec-isarray">IsArray</a></emu-xref>(<var>arg</var>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.of" type="built-in function">
<h1><span class="secnum">23.1.2.4</span> Array.of ( ...<var>items</var> )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>len</var> be the number of elements in <var>items</var>.</li><li>Let <var>lenNumber</var> be <emu-xref aoid="𝔽" id="_ref_12759"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>).</li><li>Let <var>C</var> be the <emu-val>this</emu-val> value.</li><li>If <emu-xref aoid="IsConstructor" id="_ref_12760"><a href="abstract-operations.html#sec-isconstructor">IsConstructor</a></emu-xref>(<var>C</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="Construct" id="_ref_12761"><a href="abstract-operations.html#sec-construct" class="e-user-code">Construct</a></emu-xref>(<var>C</var>, « <var>lenNumber</var>&nbsp;»).</li></ol></li><li>Else,<ol><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_12762"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(<var>len</var>).</li></ol></li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>kValue</var> be <var>items</var>[<var>k</var>].</li><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12763"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12764"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12765"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>kValue</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_12766"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <emu-val>"length"</emu-val>, <var>lenNumber</var>, <emu-val>true</emu-val>).</li><li>Return <var>A</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>This method is an intentionally generic factory method; it does not require that its <emu-val>this</emu-val> value be the Array <emu-xref href="#constructor" id="_ref_12767"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>. Therefore it can be transferred to or inherited by other <emu-xref href="#constructor" id="_ref_12768"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that may be called with a single numeric argument.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype">
<h1><span class="secnum">23.1.2.5</span> Array.prototype</h1>
<p>The value of <code>Array.prototype</code> is the <emu-xref href="#sec-properties-of-the-array-prototype-object" id="_ref_12769"><a href="indexed-collections.html#sec-properties-of-the-array-prototype-object">Array prototype object</a></emu-xref>.</p>
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
</emu-clause>
<emu-clause oldids="sec-get-array-@@species" id="sec-get-array-%symbol.species%" type="built-in function"><span id="sec-get-array-@@species"></span>
<h1><span class="secnum">23.1.2.6</span> get Array [ %Symbol.species% ]</h1>
<p><code>Array[%Symbol.species%]</code> is an <emu-xref href="#sec-object-type" id="_ref_12770"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
<emu-alg><ol><li>Return the <emu-val>this</emu-val> value.</li></ol></emu-alg>
<p>The value of the <emu-val>"name"</emu-val> property of this function is <emu-val>"get [Symbol.species]"</emu-val>.</p>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>Array prototype methods normally use their <emu-val>this</emu-val> value's <emu-xref href="#constructor" id="_ref_12771"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to create a derived object. However, a subclass <emu-xref href="#constructor" id="_ref_12772"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> may over-ride that default behaviour by redefining its <emu-xref href="#sec-well-known-symbols" id="_ref_12773"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.species%</a></emu-xref> property.</p>
</div></emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-array-prototype-object">
<h1><span class="secnum">23.1.3</span> Properties of the Array Prototype Object</h1>
<p>The <dfn tabindex="-1">Array prototype object</dfn>:</p>
<ul>
<li>is <dfn tabindex="-1">%Array.prototype%</dfn>.</li>
<li>is an <emu-xref href="#array-exotic-object" id="_ref_12774"><a href="ordinary-and-exotic-objects-behaviours.html#array-exotic-object">Array exotic object</a></emu-xref> and has the internal methods specified for such objects.</li>
<li>has a <emu-val>"length"</emu-val> property whose initial value is <emu-val>+0</emu-val><sub>𝔽</sub> and whose attributes are { <var class="field">[[Writable]]</var>: <emu-val>true</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</li>
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-object-prototype-object" id="_ref_12775"><a href="fundamental-objects.html#sec-properties-of-the-object-prototype-object">%Object.prototype%</a></emu-xref>.</li>
</ul>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>The Array prototype object is specified to be an <emu-xref href="#array-exotic-object" id="_ref_12776"><a href="ordinary-and-exotic-objects-behaviours.html#array-exotic-object">Array exotic object</a></emu-xref> to ensure compatibility with ECMAScript code that was created prior to the ECMAScript 2015 specification.</p>
</div></emu-note>
<emu-clause id="sec-array.prototype.at" type="built-in function">
<h1><span class="secnum">23.1.3.1</span> Array.prototype.at ( <var>index</var> )</h1>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12777"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12778"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>relativeIndex</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12779"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>index</var>).</li><li>If <var>relativeIndex</var> ≥ 0, then<ol><li>Let <var>k</var> be <var>relativeIndex</var>.</li></ol></li><li>Else,<ol><li>Let <var>k</var> be <var>len</var> + <var>relativeIndex</var>.</li></ol></li><li>If <var>k</var> &lt; 0 or <var>k</var><var>len</var>, return <emu-val>undefined</emu-val>.</li><li>Return ?&nbsp;<emu-xref aoid="Get" id="_ref_12780"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_12781"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12782"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>))).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.concat" type="built-in function">
<h1><span class="secnum">23.1.3.2</span> Array.prototype.concat ( ...<var>items</var> )</h1>
<p>This method returns an array containing the array elements of the object followed by the array elements of each argument.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12783"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_12784"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arrayspeciescreate" class="e-user-code">ArraySpeciesCreate</a></emu-xref>(<var>O</var>, 0).</li><li>Let <var>n</var> be 0.</li><li>Prepend <var>O</var> to <var>items</var>.</li><li>For each element <var>E</var> of <var>items</var>, do<ol><li>Let <var>spreadable</var> be ?&nbsp;<emu-xref aoid="IsConcatSpreadable" id="_ref_12785"><a href="indexed-collections.html#sec-isconcatspreadable" class="e-user-code">IsConcatSpreadable</a></emu-xref>(<var>E</var>).</li><li>If <var>spreadable</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12786"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>E</var>).</li><li>If <var>n</var> + <var>len</var> &gt; 2<sup>53</sup> - 1, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12787"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12788"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>exists</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_12789"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>E</var>, <var>Pk</var>).</li><li>If <var>exists</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>subElement</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12790"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>E</var>, <var>Pk</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12791"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_12792"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12793"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>n</var>)), <var>subElement</var>).</li></ol></li><li>Set <var>n</var> to <var>n</var> + 1.</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li></ol></li><li>Else,<ol><li>NOTE: <var>E</var> is added as a single item rather than spread.</li><li>If <var>n</var> ≥ 2<sup>53</sup> - 1, throw a <emu-val>TypeError</emu-val> exception.</li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12794"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_12795"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12796"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>n</var>)), <var>E</var>).</li><li>Set <var>n</var> to <var>n</var> + 1.</li></ol></li></ol></li><li id="step-array-proto-concat-set-length">Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_12797"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_12798"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>n</var>), <emu-val>true</emu-val>).</li><li>Return <var>A</var>.</li></ol></emu-alg>
<p>The <emu-val>"length"</emu-val> property of this method is <emu-val>1</emu-val><sub>𝔽</sub>.</p>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>The explicit setting of the <emu-val>"length"</emu-val> property in step <emu-xref href="#step-array-proto-concat-set-length" id="_ref_718"><a href="indexed-collections.html#step-array-proto-concat-set-length">6</a></emu-xref> is intended to ensure the length is correct when the final non-empty element of <var>items</var> has trailing holes or when <var>A</var> is not a built-in Array.</p>
</div></emu-note>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
<emu-clause id="sec-isconcatspreadable" type="abstract operation" aoid="IsConcatSpreadable">
<h1><span class="secnum">23.1.3.2.1</span> IsConcatSpreadable ( <var>O</var> )</h1>
<p>The abstract operation IsConcatSpreadable takes argument <var>O</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_12799"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_12800"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a Boolean or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_12801"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>If <var>O</var> <emu-xref href="#sec-object-type" id="_ref_12802"><a href="ecmascript-data-types-and-values.html#sec-object-type">is not an Object</a></emu-xref>, return <emu-val>false</emu-val>.</li><li>Let <var>spreadable</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12803"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <emu-xref href="#sec-well-known-symbols" id="_ref_12804"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.isConcatSpreadable%</a></emu-xref>).</li><li>If <var>spreadable</var> is not <emu-val>undefined</emu-val>, return <emu-xref aoid="ToBoolean" id="_ref_12805"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(<var>spreadable</var>).</li><li>Return ?&nbsp;<emu-xref aoid="IsArray" id="_ref_12806"><a href="abstract-operations.html#sec-isarray">IsArray</a></emu-xref>(<var>O</var>).</li></ol></emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-array.prototype.constructor">
<h1><span class="secnum">23.1.3.3</span> Array.prototype.constructor</h1>
<p>The initial value of <code>Array.prototype.constructor</code> is <emu-xref href="#sec-array-constructor" id="_ref_12807"><a href="indexed-collections.html#sec-array-constructor">%Array%</a></emu-xref>.</p>
</emu-clause>
<emu-clause id="sec-array.prototype.copywithin" type="built-in function">
<h1><span class="secnum">23.1.3.4</span> Array.prototype.copyWithin ( <var>target</var>, <var>start</var> [ , <var>end</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>The <var>end</var> argument is optional. If it is not provided, the length of the <emu-val>this</emu-val> value is used.</p>
</div></emu-note>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>If <var>target</var> is negative, it is treated as <emu-eqn class="inline"><var>length</var> + <var>target</var></emu-eqn> where <var>length</var> is the length of the array. If <var>start</var> is negative, it is treated as <emu-eqn class="inline"><var>length</var> + <var>start</var></emu-eqn>. If <var>end</var> is negative, it is treated as <emu-eqn class="inline"><var>length</var> + <var>end</var></emu-eqn>.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12808"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12809"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>relativeTarget</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12810"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>target</var>).</li><li>If <var>relativeTarget</var> = -∞, let <var>to</var> be 0.</li><li>Else if <var>relativeTarget</var> &lt; 0, let <var>to</var> be <emu-xref aoid="max" id="_ref_12811"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeTarget</var>, 0).</li><li>Else, let <var>to</var> be <emu-xref aoid="min" id="_ref_12812"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeTarget</var>, <var>len</var>).</li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12813"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>from</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>from</var> be <emu-xref aoid="max" id="_ref_12814"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>from</var> be <emu-xref aoid="min" id="_ref_12815"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>len</var>).</li><li>If <var>end</var> is <emu-val>undefined</emu-val>, let <var>relativeEnd</var> be <var>len</var>; else let <var>relativeEnd</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12816"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>end</var>).</li><li>If <var>relativeEnd</var> = -∞, let <var>final</var> be 0.</li><li>Else if <var>relativeEnd</var> &lt; 0, let <var>final</var> be <emu-xref aoid="max" id="_ref_12817"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeEnd</var>, 0).</li><li>Else, let <var>final</var> be <emu-xref aoid="min" id="_ref_12818"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeEnd</var>, <var>len</var>).</li><li>Let <var>count</var> be <emu-xref aoid="min" id="_ref_12819"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>final</var> - <var>from</var>, <var>len</var> - <var>to</var>).</li><li>If <var>from</var> &lt; <var>to</var> and <var>to</var> &lt; <var>from</var> + <var>count</var>, then<ol><li>Let <var>direction</var> be -1.</li><li>Set <var>from</var> to <var>from</var> + <var>count</var> - 1.</li><li>Set <var>to</var> to <var>to</var> + <var>count</var> - 1.</li></ol></li><li>Else,<ol><li>Let <var>direction</var> be 1.</li></ol></li><li>Repeat, while <var>count</var> &gt; 0,<ol><li>Let <var>fromKey</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12820"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12821"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>from</var>)).</li><li>Let <var>toKey</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12822"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12823"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>to</var>)).</li><li>Let <var>fromPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_12824"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>fromKey</var>).</li><li>If <var>fromPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12825"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>fromKey</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_12826"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>toKey</var>, <var>fromValue</var>, <emu-val>true</emu-val>).</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_12827"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>fromPresent</var> is <emu-val>false</emu-val>.</li><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_12828"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, <var>toKey</var>).</li></ol></li><li>Set <var>from</var> to <var>from</var> + <var>direction</var>.</li><li>Set <var>to</var> to <var>to</var> + <var>direction</var>.</li><li>Set <var>count</var> to <var>count</var> - 1.</li></ol></li><li>Return <var>O</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 3</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.entries" type="built-in function">
<h1><span class="secnum">23.1.3.5</span> Array.prototype.entries ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12829"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Return <emu-xref aoid="CreateArrayIterator" id="_ref_12830"><a href="indexed-collections.html#sec-createarrayiterator">CreateArrayIterator</a></emu-xref>(<var>O</var>, <emu-const>key+value</emu-const>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.every" type="built-in function">
<h1><span class="secnum">23.1.3.6</span> Array.prototype.every ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p><var>callback</var> should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. <code>every</code> calls <var>callback</var> once for each element present in the array, in ascending order, until it finds one where <var>callback</var> returns <emu-val>false</emu-val>. If such an element is found, <code>every</code> immediately returns <emu-val>false</emu-val>. Otherwise, <code>every</code> returns <emu-val>true</emu-val>. <var>callback</var> is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p>If a <var>thisArg</var> parameter is provided, it will be used as the <emu-val>this</emu-val> value for each invocation of <var>callback</var>. If it is not provided, <emu-val>undefined</emu-val> is used instead.</p>
<p><var>callback</var> is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p><code>every</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>.</p>
<p>The range of elements processed by <code>every</code> is set before the first call to <var>callback</var>. Elements which are appended to the array after the call to <code>every</code> begins will not be visited by <var>callback</var>. If existing elements of the array are changed, their value as passed to <var>callback</var> will be the value at the time <code>every</code> visits them; elements that are deleted after the call to <code>every</code> begins and before being visited are not visited. <code>every</code> acts like the "for all" quantifier in mathematics. In particular, for an empty array, it returns <emu-val>true</emu-val>.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12831"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12832"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_12833"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12834"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12835"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_12836"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12837"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>testResult</var> be <emu-xref aoid="ToBoolean" id="_ref_12838"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_12839"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_12840"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»)).</li><li>If <var>testResult</var> is <emu-val>false</emu-val>, return <emu-val>false</emu-val>.</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>true</emu-val>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.fill" type="built-in function">
<h1><span class="secnum">23.1.3.7</span> Array.prototype.fill ( <var>value</var> [ , <var>start</var> [ , <var>end</var> ] ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>The <var>start</var> argument is optional. If it is not provided, <emu-val>+0</emu-val><sub>𝔽</sub> is used.</p>
<p>The <var>end</var> argument is optional. If it is not provided, the length of the <emu-val>this</emu-val> value is used.</p>
</div></emu-note>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>If <var>start</var> is negative, it is treated as <emu-eqn class="inline"><var>length</var> + <var>start</var></emu-eqn> where <var>length</var> is the length of the array. If <var>end</var> is negative, it is treated as <emu-eqn class="inline"><var>length</var> + <var>end</var></emu-eqn>.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12841"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12842"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12843"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>k</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>k</var> be <emu-xref aoid="max" id="_ref_12844"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>k</var> be <emu-xref aoid="min" id="_ref_12845"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>len</var>).</li><li>If <var>end</var> is <emu-val>undefined</emu-val>, let <var>relativeEnd</var> be <var>len</var>; else let <var>relativeEnd</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12846"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>end</var>).</li><li>If <var>relativeEnd</var> = -∞, let <var>final</var> be 0.</li><li>Else if <var>relativeEnd</var> &lt; 0, let <var>final</var> be <emu-xref aoid="max" id="_ref_12847"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeEnd</var>, 0).</li><li>Else, let <var>final</var> be <emu-xref aoid="min" id="_ref_12848"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeEnd</var>, <var>len</var>).</li><li>Repeat, while <var>k</var> &lt; <var>final</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12849"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12850"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_12851"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>Pk</var>, <var>value</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>O</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 3</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.filter" type="built-in function">
<h1><span class="secnum">23.1.3.8</span> Array.prototype.filter ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p><var>callback</var> should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. <code>filter</code> calls <var>callback</var> once for each element in the array, in ascending order, and constructs a new array of all the values for which <var>callback</var> returns <emu-val>true</emu-val>. <var>callback</var> is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p>If a <var>thisArg</var> parameter is provided, it will be used as the <emu-val>this</emu-val> value for each invocation of <var>callback</var>. If it is not provided, <emu-val>undefined</emu-val> is used instead.</p>
<p><var>callback</var> is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p><code>filter</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>.</p>
<p>The range of elements processed by <code>filter</code> is set before the first call to <var>callback</var>. Elements which are appended to the array after the call to <code>filter</code> begins will not be visited by <var>callback</var>. If existing elements of the array are changed their value as passed to <var>callback</var> will be the value at the time <code>filter</code> visits them; elements that are deleted after the call to <code>filter</code> begins and before being visited are not visited.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12852"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12853"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_12854"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_12855"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arrayspeciescreate" class="e-user-code">ArraySpeciesCreate</a></emu-xref>(<var>O</var>, 0).</li><li>Let <var>k</var> be 0.</li><li>Let <var>to</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12856"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12857"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_12858"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12859"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>selected</var> be <emu-xref aoid="ToBoolean" id="_ref_12860"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_12861"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_12862"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»)).</li><li>If <var>selected</var> is <emu-val>true</emu-val>, then<ol><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12863"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_12864"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12865"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>to</var>)), <var>kValue</var>).</li><li>Set <var>to</var> to <var>to</var> + 1.</li></ol></li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.find" type="built-in function">
<h1><span class="secnum">23.1.3.9</span> Array.prototype.find ( <var>predicate</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method calls <var>predicate</var> once for each element of the array, in ascending index order, until it finds one where <var>predicate</var> returns a value that coerces to <emu-val>true</emu-val>. If such an element is found, <code>find</code> immediately returns that element value. Otherwise, <code>find</code> returns <emu-val>undefined</emu-val>.</p>
<p>See <emu-xref aoid="FindViaPredicate" id="_ref_12866"><a href="indexed-collections.html#sec-findviapredicate">FindViaPredicate</a></emu-xref> for additional information.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12867"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12868"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>findRec</var> be ?&nbsp;<emu-xref aoid="FindViaPredicate" id="_ref_12869"><a href="indexed-collections.html#sec-findviapredicate" class="e-user-code">FindViaPredicate</a></emu-xref>(<var>O</var>, <var>len</var>, <emu-const>ascending</emu-const>, <var>predicate</var>, <var>thisArg</var>).</li><li>Return <var>findRec</var>.<var class="field">[[Value]]</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.findindex" type="built-in function">
<h1><span class="secnum">23.1.3.10</span> Array.prototype.findIndex ( <var>predicate</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method calls <var>predicate</var> once for each element of the array, in ascending index order, until it finds one where <var>predicate</var> returns a value that coerces to <emu-val>true</emu-val>. If such an element is found, <code>findIndex</code> immediately returns the index of that element value. Otherwise, <code>findIndex</code> returns -1.</p>
<p>See <emu-xref aoid="FindViaPredicate" id="_ref_12870"><a href="indexed-collections.html#sec-findviapredicate">FindViaPredicate</a></emu-xref> for additional information.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12871"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12872"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>findRec</var> be ?&nbsp;<emu-xref aoid="FindViaPredicate" id="_ref_12873"><a href="indexed-collections.html#sec-findviapredicate" class="e-user-code">FindViaPredicate</a></emu-xref>(<var>O</var>, <var>len</var>, <emu-const>ascending</emu-const>, <var>predicate</var>, <var>thisArg</var>).</li><li>Return <var>findRec</var>.<var class="field">[[Index]]</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.findlast" type="built-in function">
<h1><span class="secnum">23.1.3.11</span> Array.prototype.findLast ( <var>predicate</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method calls <var>predicate</var> once for each element of the array, in descending index order, until it finds one where <var>predicate</var> returns a value that coerces to <emu-val>true</emu-val>. If such an element is found, <code>findLast</code> immediately returns that element value. Otherwise, <code>findLast</code> returns <emu-val>undefined</emu-val>.</p>
<p>See <emu-xref aoid="FindViaPredicate" id="_ref_12874"><a href="indexed-collections.html#sec-findviapredicate">FindViaPredicate</a></emu-xref> for additional information.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12875"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12876"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>findRec</var> be ?&nbsp;<emu-xref aoid="FindViaPredicate" id="_ref_12877"><a href="indexed-collections.html#sec-findviapredicate" class="e-user-code">FindViaPredicate</a></emu-xref>(<var>O</var>, <var>len</var>, <emu-const>descending</emu-const>, <var>predicate</var>, <var>thisArg</var>).</li><li>Return <var>findRec</var>.<var class="field">[[Value]]</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.findlastindex" type="built-in function">
<h1><span class="secnum">23.1.3.12</span> Array.prototype.findLastIndex ( <var>predicate</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method calls <var>predicate</var> once for each element of the array, in descending index order, until it finds one where <var>predicate</var> returns a value that coerces to <emu-val>true</emu-val>. If such an element is found, <code>findLastIndex</code> immediately returns the index of that element value. Otherwise, <code>findLastIndex</code> returns -1.</p>
<p>See <emu-xref aoid="FindViaPredicate" id="_ref_12878"><a href="indexed-collections.html#sec-findviapredicate">FindViaPredicate</a></emu-xref> for additional information.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12879"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12880"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>findRec</var> be ?&nbsp;<emu-xref aoid="FindViaPredicate" id="_ref_12881"><a href="indexed-collections.html#sec-findviapredicate" class="e-user-code">FindViaPredicate</a></emu-xref>(<var>O</var>, <var>len</var>, <emu-const>descending</emu-const>, <var>predicate</var>, <var>thisArg</var>).</li><li>Return <var>findRec</var>.<var class="field">[[Index]]</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
<emu-clause id="sec-findviapredicate" type="abstract operation" aoid="FindViaPredicate">
<h1><span class="secnum">23.1.3.12.1</span> FindViaPredicate ( <var>O</var>, <var>len</var>, <var>direction</var>, <var>predicate</var>, <var>thisArg</var> )</h1>
<p>The abstract operation FindViaPredicate takes arguments <var>O</var> (an Object), <var>len</var> (a non-negative <emu-xref href="#integer" id="_ref_12882"><a href="notational-conventions.html#integer">integer</a></emu-xref>), <var>direction</var> (<emu-const>ascending</emu-const> or <emu-const>descending</emu-const>), <var>predicate</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_12883"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>), and <var>thisArg</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_12884"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_12885"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_12886"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> with fields <var class="field">[[Index]]</var> (an <emu-xref href="#integral-number" id="_ref_12887"><a href="notational-conventions.html#integral-number">integral Number</a></emu-xref>) and <var class="field">[[Value]]</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_12888"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_12889"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>.</p>
<p><var>O</var> should be an <emu-xref href="#sec-lengthofarraylike" id="_ref_12890"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref> or a <emu-xref href="#typedarray" id="_ref_12891"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>. This operation calls <var>predicate</var> once for each element of <var>O</var>, in either ascending index order or descending index order (as indicated by <var>direction</var>), until it finds one where <var>predicate</var> returns a value that coerces to <emu-val>true</emu-val>. At that point, this operation returns a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_12892"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> that gives the index and value of the element found. If no such element is found, this operation returns a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_12893"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> that specifies <emu-val>-1</emu-val><sub>𝔽</sub> for the index and <emu-val>undefined</emu-val> for the value.</p>
<p><var>predicate</var> should be a function. When called for an element of the array, it is passed three arguments: the value of the element, the index of the element, and the object being traversed. Its return value will be coerced to a Boolean value.</p>
<p><var>thisArg</var> will be used as the <emu-val>this</emu-val> value for each invocation of <var>predicate</var>.</p>
<p>This operation does not directly mutate the object on which it is called, but the object may be mutated by the calls to <var>predicate</var>.</p>
<p>The range of elements processed is set before the first call to <var>predicate</var>, just before the traversal begins. Elements that are appended to the array after this will not be visited by <var>predicate</var>. If existing elements of the array are changed, their value as passed to <var>predicate</var> will be the value at the time that this operation visits them. Elements that are deleted after traversal begins and before being visited are still visited and are either looked up from the prototype or are <emu-val>undefined</emu-val>.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>If <emu-xref aoid="IsCallable" id="_ref_12894"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>predicate</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <var>direction</var> is <emu-const>ascending</emu-const>, then<ol><li>Let <var>indices</var> be a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_12895"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of the <emu-xref href="#integer" id="_ref_12896"><a href="notational-conventions.html#integer">integers</a></emu-xref> in the <emu-xref href="#interval" id="_ref_12897"><a href="notational-conventions.html#interval">interval</a></emu-xref> from 0 (inclusive) to <var>len</var> (exclusive), in ascending order.</li></ol></li><li>Else,<ol><li>Let <var>indices</var> be a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_12898"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of the <emu-xref href="#integer" id="_ref_12899"><a href="notational-conventions.html#integer">integers</a></emu-xref> in the <emu-xref href="#interval" id="_ref_12900"><a href="notational-conventions.html#interval">interval</a></emu-xref> from 0 (inclusive) to <var>len</var> (exclusive), in descending order.</li></ol></li><li>For each <emu-xref href="#integer" id="_ref_12901"><a href="notational-conventions.html#integer">integer</a></emu-xref> <var>k</var> of <var>indices</var>, do<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12902"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12903"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>NOTE: If <var>O</var> is a <emu-xref href="#typedarray" id="_ref_12904"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>, the following invocation of <emu-xref aoid="Get" id="_ref_12905"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref> will return a <emu-xref href="#sec-completion-record-specification-type" id="_ref_12906"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion</a></emu-xref>.</li><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12907"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>testResult</var> be ?&nbsp;<emu-xref aoid="Call" id="_ref_12908"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>predicate</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_12909"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li><li>If <emu-xref aoid="ToBoolean" id="_ref_12910"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(<var>testResult</var>) is <emu-val>true</emu-val>, return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_12911"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Index]]</var>: <emu-xref aoid="𝔽" id="_ref_12912"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var class="field">[[Value]]</var>: <var>kValue</var>&nbsp;}.</li></ol></li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_12913"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Index]]</var>: <emu-val>-1</emu-val><sub>𝔽</sub>, <var class="field">[[Value]]</var>: <emu-val>undefined</emu-val>&nbsp;}.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-array.prototype.flat" type="built-in function">
<h1><span class="secnum">23.1.3.13</span> Array.prototype.flat ( [ <var>depth</var> ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12914"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>sourceLen</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12915"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>depthNum</var> be 1.</li><li>If <var>depth</var> is not <emu-val>undefined</emu-val>, then<ol><li>Set <var>depthNum</var> to ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12916"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>depth</var>).</li><li>If <var>depthNum</var> &lt; 0, set <var>depthNum</var> to 0.</li></ol></li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_12917"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arrayspeciescreate" class="e-user-code">ArraySpeciesCreate</a></emu-xref>(<var>O</var>, 0).</li><li>Perform ?&nbsp;<emu-xref aoid="FlattenIntoArray" id="_ref_12918"><a href="indexed-collections.html#sec-flattenintoarray" class="e-user-code">FlattenIntoArray</a></emu-xref>(<var>A</var>, <var>O</var>, <var>sourceLen</var>, 0, <var>depthNum</var>).</li><li>Return <var>A</var>.</li></ol></emu-alg>
<emu-clause id="sec-flattenintoarray" type="abstract operation" aoid="FlattenIntoArray">
<h1><span class="secnum">23.1.3.13.1</span> FlattenIntoArray ( <var>target</var>, <var>source</var>, <var>sourceLen</var>, <var>start</var>, <var>depth</var> [ , <var>mapperFunction</var> [ , <var>thisArg</var> ] ] )</h1>
<p>The abstract operation FlattenIntoArray takes arguments <var>target</var> (an Object), <var>source</var> (an Object), <var>sourceLen</var> (a non-negative <emu-xref href="#integer" id="_ref_12919"><a href="notational-conventions.html#integer">integer</a></emu-xref>), <var>start</var> (a non-negative <emu-xref href="#integer" id="_ref_12920"><a href="notational-conventions.html#integer">integer</a></emu-xref>), and <var>depth</var> (a non-negative <emu-xref href="#integer" id="_ref_12921"><a href="notational-conventions.html#integer">integer</a></emu-xref> or +∞) and optional arguments <var>mapperFunction</var> (a <emu-xref href="#function-object" id="_ref_12922"><a href="ecmascript-data-types-and-values.html#function-object">function object</a></emu-xref>) and <var>thisArg</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_12923"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_12924"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a non-negative <emu-xref href="#integer" id="_ref_12925"><a href="notational-conventions.html#integer">integer</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_12926"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li><emu-xref href="#assert" id="_ref_12927"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: If <var>mapperFunction</var> is present, then <emu-xref aoid="IsCallable" id="_ref_12928"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>mapperFunction</var>) is <emu-val>true</emu-val>, <var>thisArg</var> is present, and <var>depth</var> is 1.</li><li>Let <var>targetIndex</var> be <var>start</var>.</li><li>Let <var>sourceIndex</var> be <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>Repeat, while <emu-xref aoid="" id="_ref_12929"><a href="notational-conventions.html#%E2%84%9D"></a></emu-xref>(<var>sourceIndex</var>) &lt; <var>sourceLen</var>,<ol><li>Let <var>P</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12930"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<var>sourceIndex</var>).</li><li>Let <var>exists</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_12931"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>source</var>, <var>P</var>).</li><li>If <var>exists</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>element</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12932"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>source</var>, <var>P</var>).</li><li>If <var>mapperFunction</var> is present, then<ol><li>Set <var>element</var> to ?&nbsp;<emu-xref aoid="Call" id="_ref_12933"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>mapperFunction</var>, <var>thisArg</var>, « <var>element</var>, <var>sourceIndex</var>, <var>source</var>&nbsp;»).</li></ol></li><li>Let <var>shouldFlatten</var> be <emu-val>false</emu-val>.</li><li>If <var>depth</var> &gt; 0, then<ol><li>Set <var>shouldFlatten</var> to ?&nbsp;<emu-xref aoid="IsArray" id="_ref_12934"><a href="abstract-operations.html#sec-isarray">IsArray</a></emu-xref>(<var>element</var>).</li></ol></li><li>If <var>shouldFlatten</var> is <emu-val>true</emu-val>, then<ol><li>If <var>depth</var> = +∞, let <var>newDepth</var> be +∞.</li><li>Else, let <var>newDepth</var> be <var>depth</var> - 1.</li><li>Let <var>elementLen</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12935"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>element</var>).</li><li>Set <var>targetIndex</var> to ?&nbsp;<emu-xref aoid="FlattenIntoArray" id="_ref_12936"><a href="indexed-collections.html#sec-flattenintoarray" class="e-user-code">FlattenIntoArray</a></emu-xref>(<var>target</var>, <var>element</var>, <var>elementLen</var>, <var>targetIndex</var>, <var>newDepth</var>).</li></ol></li><li>Else,<ol><li>If <var>targetIndex</var> ≥ 2<sup>53</sup> - 1, throw a <emu-val>TypeError</emu-val> exception.</li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_12937"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>target</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_12938"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12939"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>targetIndex</var>)), <var>element</var>).</li><li>Set <var>targetIndex</var> to <var>targetIndex</var> + 1.</li></ol></li></ol></li><li>Set <var>sourceIndex</var> to <var>sourceIndex</var> + <emu-val>1</emu-val><sub>𝔽</sub>.</li></ol></li><li>Return <var>targetIndex</var>.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-array.prototype.flatmap" type="built-in function">
<h1><span class="secnum">23.1.3.14</span> Array.prototype.flatMap ( <var>mapperFunction</var> [ , <var>thisArg</var> ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12940"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>sourceLen</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12941"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_12942"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>mapperFunction</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_12943"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arrayspeciescreate" class="e-user-code">ArraySpeciesCreate</a></emu-xref>(<var>O</var>, 0).</li><li>Perform ?&nbsp;<emu-xref aoid="FlattenIntoArray" id="_ref_12944"><a href="indexed-collections.html#sec-flattenintoarray" class="e-user-code">FlattenIntoArray</a></emu-xref>(<var>A</var>, <var>O</var>, <var>sourceLen</var>, 0, 1, <var>mapperFunction</var>, <var>thisArg</var>).</li><li>Return <var>A</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.foreach" type="built-in function">
<h1><span class="secnum">23.1.3.15</span> Array.prototype.forEach ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p><var>callback</var> should be a function that accepts three arguments. <code>forEach</code> calls <var>callback</var> once for each element present in the array, in ascending order. <var>callback</var> is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p>If a <var>thisArg</var> parameter is provided, it will be used as the <emu-val>this</emu-val> value for each invocation of <var>callback</var>. If it is not provided, <emu-val>undefined</emu-val> is used instead.</p>
<p><var>callback</var> is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p><code>forEach</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>.</p>
<p>The range of elements processed by <code>forEach</code> is set before the first call to <var>callback</var>. Elements which are appended to the array after the call to <code>forEach</code> begins will not be visited by <var>callback</var>. If existing elements of the array are changed, their value as passed to <var>callback</var> will be the value at the time <code>forEach</code> visits them; elements that are deleted after the call to <code>forEach</code> begins and before being visited are not visited.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12945"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12946"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_12947"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12948"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12949"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_12950"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12951"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Call" id="_ref_12952"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_12953"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.includes" type="built-in function">
<h1><span class="secnum">23.1.3.16</span> Array.prototype.includes ( <var>searchElement</var> [ , <var>fromIndex</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method compares <var>searchElement</var> to the elements of the array, in ascending order, using the <emu-xref aoid="SameValueZero" id="_ref_12954"><a href="abstract-operations.html#sec-samevaluezero">SameValueZero</a></emu-xref> algorithm, and if found at any position, returns <emu-val>true</emu-val>; otherwise, it returns <emu-val>false</emu-val>.</p>
<p>The optional second argument <var>fromIndex</var> defaults to <emu-val>+0</emu-val><sub>𝔽</sub> (i.e. the whole array is searched). If it is greater than or equal to the length of the array, <emu-val>false</emu-val> is returned, i.e. the array will not be searched. If it is less than <emu-val>-0</emu-val><sub>𝔽</sub>, it is used as the offset from the end of the array to compute <var>fromIndex</var>. If the computed index is less than or equal to <emu-val>+0</emu-val><sub>𝔽</sub>, the whole array will be searched.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12955"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12956"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <var>len</var> = 0, return <emu-val>false</emu-val>.</li><li>Let <var>n</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12957"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>fromIndex</var>).</li><li><emu-xref href="#assert" id="_ref_12958"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: If <var>fromIndex</var> is <emu-val>undefined</emu-val>, then <var>n</var> is 0.</li><li>If <var>n</var> = +∞, return <emu-val>false</emu-val>.</li><li>If <var>n</var> = -∞, set <var>n</var> to 0.</li><li>If <var>n</var> ≥ 0, then<ol><li>Let <var>k</var> be <var>n</var>.</li></ol></li><li>Else,<ol><li>Let <var>k</var> be <var>len</var> + <var>n</var>.</li><li>If <var>k</var> &lt; 0, set <var>k</var> to 0.</li></ol></li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>elementK</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12959"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_12960"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12961"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>))).</li><li>If <emu-xref aoid="SameValueZero" id="_ref_12962"><a href="abstract-operations.html#sec-samevaluezero">SameValueZero</a></emu-xref>(<var>searchElement</var>, <var>elementK</var>) is <emu-val>true</emu-val>, return <emu-val>true</emu-val>.</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
<emu-note><span class="note">Note 3</span><div class="note-contents">
<p>This method intentionally differs from the similar <code>indexOf</code> method in two ways. First, it uses the <emu-xref aoid="SameValueZero" id="_ref_12963"><a href="abstract-operations.html#sec-samevaluezero">SameValueZero</a></emu-xref> algorithm, instead of <emu-xref aoid="IsStrictlyEqual" id="_ref_12964"><a href="abstract-operations.html#sec-isstrictlyequal">IsStrictlyEqual</a></emu-xref>, allowing it to detect <emu-val>NaN</emu-val> array elements. Second, it does not skip missing array elements, instead treating them as <emu-val>undefined</emu-val>.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.indexof" type="built-in function">
<h1><span class="secnum">23.1.3.17</span> Array.prototype.indexOf ( <var>searchElement</var> [ , <var>fromIndex</var> ] )</h1>
<p>This method compares <var>searchElement</var> to the elements of the array, in ascending order, using the <emu-xref aoid="IsStrictlyEqual" id="_ref_12965"><a href="abstract-operations.html#sec-isstrictlyequal">IsStrictlyEqual</a></emu-xref> algorithm, and if found at one or more indices, returns the smallest such index; otherwise, it returns <emu-val>-1</emu-val><sub>𝔽</sub>.</p>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>The optional second argument <var>fromIndex</var> defaults to <emu-val>+0</emu-val><sub>𝔽</sub> (i.e. the whole array is searched). If it is greater than or equal to the length of the array, <emu-val>-1</emu-val><sub>𝔽</sub> is returned, i.e. the array will not be searched. If it is less than <emu-val>-0</emu-val><sub>𝔽</sub>, it is used as the offset from the end of the array to compute <var>fromIndex</var>. If the computed index is less than or equal to <emu-val>+0</emu-val><sub>𝔽</sub>, the whole array will be searched.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12966"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12967"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <var>len</var> = 0, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>Let <var>n</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12968"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>fromIndex</var>).</li><li><emu-xref href="#assert" id="_ref_12969"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: If <var>fromIndex</var> is <emu-val>undefined</emu-val>, then <var>n</var> is 0.</li><li>If <var>n</var> = +∞, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>n</var> = -∞, set <var>n</var> to 0.</li><li>If <var>n</var> ≥ 0, then<ol><li>Let <var>k</var> be <var>n</var>.</li></ol></li><li>Else,<ol><li>Let <var>k</var> be <var>len</var> + <var>n</var>.</li><li>If <var>k</var> &lt; 0, set <var>k</var> to 0.</li></ol></li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12970"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12971"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_12972"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>elementK</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12973"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <emu-xref aoid="IsStrictlyEqual" id="_ref_12974"><a href="abstract-operations.html#sec-isstrictlyequal">IsStrictlyEqual</a></emu-xref>(<var>searchElement</var>, <var>elementK</var>) is <emu-val>true</emu-val>, return <emu-xref aoid="𝔽" id="_ref_12975"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>-1</emu-val><sub>𝔽</sub>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.join" type="built-in function">
<h1><span class="secnum">23.1.3.18</span> Array.prototype.join ( <var>separator</var> )</h1>
<p>This method converts the elements of the array to Strings, and then concatenates these Strings, separated by occurrences of the <var>separator</var>. If no separator is provided, a single comma is used as the separator.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12976"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12977"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <var>separator</var> is <emu-val>undefined</emu-val>, let <var>sep</var> be <emu-val>","</emu-val>.</li><li>Else, let <var>sep</var> be ?&nbsp;<emu-xref aoid="ToString" id="_ref_12978"><a href="abstract-operations.html#sec-tostring" class="e-user-code">ToString</a></emu-xref>(<var>separator</var>).</li><li>Let <var>R</var> be the empty String.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>If <var>k</var> &gt; 0, set <var>R</var> to the <emu-xref href="#string-concatenation" id="_ref_12979"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>R</var> and <var>sep</var>.</li><li>Let <var>element</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12980"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_12981"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12982"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>))).</li><li>If <var>element</var> is neither <emu-val>undefined</emu-val> nor <emu-val>null</emu-val>, then<ol><li>Let <var>S</var> be ?&nbsp;<emu-xref aoid="ToString" id="_ref_12983"><a href="abstract-operations.html#sec-tostring" class="e-user-code">ToString</a></emu-xref>(<var>element</var>).</li><li>Set <var>R</var> to the <emu-xref href="#string-concatenation" id="_ref_12984"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>R</var> and <var>S</var>.</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>R</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore, it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.keys" type="built-in function">
<h1><span class="secnum">23.1.3.19</span> Array.prototype.keys ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12985"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Return <emu-xref aoid="CreateArrayIterator" id="_ref_12986"><a href="indexed-collections.html#sec-createarrayiterator">CreateArrayIterator</a></emu-xref>(<var>O</var>, <emu-const>key</emu-const>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.lastindexof" type="built-in function">
<h1><span class="secnum">23.1.3.20</span> Array.prototype.lastIndexOf ( <var>searchElement</var> [ , <var>fromIndex</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method compares <var>searchElement</var> to the elements of the array in descending order using the <emu-xref aoid="IsStrictlyEqual" id="_ref_12987"><a href="abstract-operations.html#sec-isstrictlyequal">IsStrictlyEqual</a></emu-xref> algorithm, and if found at one or more indices, returns the largest such index; otherwise, it returns <emu-val>-1</emu-val><sub>𝔽</sub>.</p>
<p>The optional second argument <var>fromIndex</var> defaults to the array's length minus one (i.e. the whole array is searched). If it is greater than or equal to the length of the array, the whole array will be searched. If it is less than <emu-val>-0</emu-val><sub>𝔽</sub>, it is used as the offset from the end of the array to compute <var>fromIndex</var>. If the computed index is less than or equal to <emu-val>+0</emu-val><sub>𝔽</sub>, <emu-val>-1</emu-val><sub>𝔽</sub> is returned.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12988"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12989"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <var>len</var> = 0, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>fromIndex</var> is present, let <var>n</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_12990"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>fromIndex</var>); else let <var>n</var> be <var>len</var> - 1.</li><li>If <var>n</var> = -∞, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>n</var> ≥ 0, then<ol><li>Let <var>k</var> be <emu-xref aoid="min" id="_ref_12991"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>n</var>, <var>len</var> - 1).</li></ol></li><li>Else,<ol><li>Let <var>k</var> be <var>len</var> + <var>n</var>.</li></ol></li><li>Repeat, while <var>k</var> ≥ 0,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_12992"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_12993"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_12994"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>elementK</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_12995"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <emu-xref aoid="IsStrictlyEqual" id="_ref_12996"><a href="abstract-operations.html#sec-isstrictlyequal">IsStrictlyEqual</a></emu-xref>(<var>searchElement</var>, <var>elementK</var>) is <emu-val>true</emu-val>, return <emu-xref aoid="𝔽" id="_ref_12997"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li><li>Return <emu-val>-1</emu-val><sub>𝔽</sub>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.map" type="built-in function">
<h1><span class="secnum">23.1.3.21</span> Array.prototype.map ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p><var>callback</var> should be a function that accepts three arguments. <code>map</code> calls <var>callback</var> once for each element in the array, in ascending order, and constructs a new Array from the results. <var>callback</var> is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p>If a <var>thisArg</var> parameter is provided, it will be used as the <emu-val>this</emu-val> value for each invocation of <var>callback</var>. If it is not provided, <emu-val>undefined</emu-val> is used instead.</p>
<p><var>callback</var> is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p><code>map</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>.</p>
<p>The range of elements processed by <code>map</code> is set before the first call to <var>callback</var>. Elements which are appended to the array after the call to <code>map</code> begins will not be visited by <var>callback</var>. If existing elements of the array are changed, their value as passed to <var>callback</var> will be the value at the time <code>map</code> visits them; elements that are deleted after the call to <code>map</code> begins and before being visited are not visited.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_12998"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_12999"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13000"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_13001"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arrayspeciescreate" class="e-user-code">ArraySpeciesCreate</a></emu-xref>(<var>O</var>, <var>len</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13002"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13003"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13004"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13005"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>mappedValue</var> be ?&nbsp;<emu-xref aoid="Call" id="_ref_13006"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13007"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13008"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>mappedValue</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.pop" type="built-in function">
<h1><span class="secnum">23.1.3.22</span> Array.prototype.pop ( )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method removes the last element of the array and returns it.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13009"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13010"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <var>len</var> = 0, then<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13011"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <emu-val>"length"</emu-val>, <emu-val>+0</emu-val><sub>𝔽</sub>, <emu-val>true</emu-val>).</li><li>Return <emu-val>undefined</emu-val>.</li></ol></li><li><emu-xref href="#assert" id="_ref_13012"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>len</var> &gt; 0.</li><li>Let <var>newLen</var> be <emu-xref aoid="𝔽" id="_ref_13013"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var> - 1).</li><li>Let <var>index</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13014"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<var>newLen</var>).</li><li>Let <var>element</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13015"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>index</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13016"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, <var>index</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13017"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <emu-val>"length"</emu-val>, <var>newLen</var>, <emu-val>true</emu-val>).</li><li>Return <var>element</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.push" type="built-in function">
<h1><span class="secnum">23.1.3.23</span> Array.prototype.push ( ...<var>items</var> )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method appends the arguments to the end of the array, in the order in which they appear. It returns the new length of the array.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13018"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13019"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>argCount</var> be the number of elements in <var>items</var>.</li><li>If <var>len</var> + <var>argCount</var> &gt; 2<sup>53</sup> - 1, throw a <emu-val>TypeError</emu-val> exception.</li><li>For each element <var>E</var> of <var>items</var>, do<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13020"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13021"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13022"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>)), <var>E</var>, <emu-val>true</emu-val>).</li><li>Set <var>len</var> to <var>len</var> + 1.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13023"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_13024"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>), <emu-val>true</emu-val>).</li><li>Return <emu-xref aoid="𝔽" id="_ref_13025"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>).</li></ol></emu-alg>
<p>The <emu-val>"length"</emu-val> property of this method is <emu-val>1</emu-val><sub>𝔽</sub>.</p>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.reduce" type="built-in function">
<h1><span class="secnum">23.1.3.24</span> Array.prototype.reduce ( <var>callback</var> [ , <var>initialValue</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p><var>callback</var> should be a function that takes four arguments. <code>reduce</code> calls the callback, as a function, once for each element after the first element present in the array, in ascending order.</p>
<p><var>callback</var> is called with four arguments: the <var>previousValue</var> (value from the previous call to <var>callback</var>), the <var>currentValue</var> (value of the current element), the <var>currentIndex</var>, and the object being traversed. The first time that callback is called, the <var>previousValue</var> and <var>currentValue</var> can be one of two values. If an <var>initialValue</var> was supplied in the call to <code>reduce</code>, then <var>previousValue</var> will be <var>initialValue</var> and <var>currentValue</var> will be the first value in the array. If no <var>initialValue</var> was supplied, then <var>previousValue</var> will be the first value in the array and <var>currentValue</var> will be the second. It is a <emu-val>TypeError</emu-val> if the array contains no elements and <var>initialValue</var> is not provided.</p>
<p><code>reduce</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>.</p>
<p>The range of elements processed by <code>reduce</code> is set before the first call to <var>callback</var>. Elements that are appended to the array after the call to <code>reduce</code> begins will not be visited by <var>callback</var>. If existing elements of the array are changed, their value as passed to <var>callback</var> will be the value at the time <code>reduce</code> visits them; elements that are deleted after the call to <code>reduce</code> begins and before being visited are not visited.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13026"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13027"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13028"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <var>len</var> = 0 and <var>initialValue</var> is not present, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Let <var>accumulator</var> be <emu-val>undefined</emu-val>.</li><li>If <var>initialValue</var> is present, then<ol><li>Set <var>accumulator</var> to <var>initialValue</var>.</li></ol></li><li>Else,<ol><li>Let <var>kPresent</var> be <emu-val>false</emu-val>.</li><li>Repeat, while <var>kPresent</var> is <emu-val>false</emu-val> and <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13029"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13030"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Set <var>kPresent</var> to ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13031"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Set <var>accumulator</var> to ?&nbsp;<emu-xref aoid="Get" id="_ref_13032"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>If <var>kPresent</var> is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li></ol></li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13033"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13034"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13035"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13036"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Set <var>accumulator</var> to ?&nbsp;<emu-xref aoid="Call" id="_ref_13037"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <emu-val>undefined</emu-val>, « <var>accumulator</var>, <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13038"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>accumulator</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.reduceright" type="built-in function">
<h1><span class="secnum">23.1.3.25</span> Array.prototype.reduceRight ( <var>callback</var> [ , <var>initialValue</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p><var>callback</var> should be a function that takes four arguments. <code>reduceRight</code> calls the callback, as a function, once for each element after the first element present in the array, in descending order.</p>
<p><var>callback</var> is called with four arguments: the <var>previousValue</var> (value from the previous call to <var>callback</var>), the <var>currentValue</var> (value of the current element), the <var>currentIndex</var>, and the object being traversed. The first time the function is called, the <var>previousValue</var> and <var>currentValue</var> can be one of two values. If an <var>initialValue</var> was supplied in the call to <code>reduceRight</code>, then <var>previousValue</var> will be <var>initialValue</var> and <var>currentValue</var> will be the last value in the array. If no <var>initialValue</var> was supplied, then <var>previousValue</var> will be the last value in the array and <var>currentValue</var> will be the second-to-last value. It is a <emu-val>TypeError</emu-val> if the array contains no elements and <var>initialValue</var> is not provided.</p>
<p><code>reduceRight</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>.</p>
<p>The range of elements processed by <code>reduceRight</code> is set before the first call to <var>callback</var>. Elements that are appended to the array after the call to <code>reduceRight</code> begins will not be visited by <var>callback</var>. If existing elements of the array are changed by <var>callback</var>, their value as passed to <var>callback</var> will be the value at the time <code>reduceRight</code> visits them; elements that are deleted after the call to <code>reduceRight</code> begins and before being visited are not visited.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13039"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13040"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13041"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <var>len</var> = 0 and <var>initialValue</var> is not present, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be <var>len</var> - 1.</li><li>Let <var>accumulator</var> be <emu-val>undefined</emu-val>.</li><li>If <var>initialValue</var> is present, then<ol><li>Set <var>accumulator</var> to <var>initialValue</var>.</li></ol></li><li>Else,<ol><li>Let <var>kPresent</var> be <emu-val>false</emu-val>.</li><li>Repeat, while <var>kPresent</var> is <emu-val>false</emu-val> and <var>k</var> ≥ 0,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13042"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13043"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Set <var>kPresent</var> to ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13044"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Set <var>accumulator</var> to ?&nbsp;<emu-xref aoid="Get" id="_ref_13045"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li><li>If <var>kPresent</var> is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li></ol></li><li>Repeat, while <var>k</var> ≥ 0,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13046"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13047"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13048"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13049"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Set <var>accumulator</var> to ?&nbsp;<emu-xref aoid="Call" id="_ref_13050"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <emu-val>undefined</emu-val>, « <var>accumulator</var>, <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13051"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li></ol></li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li><li>Return <var>accumulator</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.reverse" type="built-in function">
<h1><span class="secnum">23.1.3.26</span> Array.prototype.reverse ( )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method rearranges the elements of the array so as to reverse their order. It returns the reversed array.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13052"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13053"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>middle</var> be <emu-xref aoid="floor" id="_ref_13054"><a href="notational-conventions.html#eqn-floor">floor</a></emu-xref>(<var>len</var> / 2).</li><li>Let <var>lower</var> be 0.</li><li>Repeat, while <var>lower</var><var>middle</var>,<ol><li>Let <var>upper</var> be <var>len</var> - <var>lower</var> - 1.</li><li>Let <var>upperP</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13055"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13056"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>upper</var>)).</li><li>Let <var>lowerP</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13057"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13058"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>lower</var>)).</li><li>Let <var>lowerExists</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13059"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>lowerP</var>).</li><li>If <var>lowerExists</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>lowerValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13060"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>lowerP</var>).</li></ol></li><li>Let <var>upperExists</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13061"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>upperP</var>).</li><li>If <var>upperExists</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>upperValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13062"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>upperP</var>).</li></ol></li><li>If <var>lowerExists</var> is <emu-val>true</emu-val> and <var>upperExists</var> is <emu-val>true</emu-val>, then<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13063"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>lowerP</var>, <var>upperValue</var>, <emu-val>true</emu-val>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13064"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>upperP</var>, <var>lowerValue</var>, <emu-val>true</emu-val>).</li></ol></li><li>Else if <var>lowerExists</var> is <emu-val>false</emu-val> and <var>upperExists</var> is <emu-val>true</emu-val>, then<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13065"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>lowerP</var>, <var>upperValue</var>, <emu-val>true</emu-val>).</li><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13066"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, <var>upperP</var>).</li></ol></li><li>Else if <var>lowerExists</var> is <emu-val>true</emu-val> and <var>upperExists</var> is <emu-val>false</emu-val>, then<ol><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13067"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, <var>lowerP</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13068"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>upperP</var>, <var>lowerValue</var>, <emu-val>true</emu-val>).</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_13069"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>lowerExists</var> and <var>upperExists</var> are both <emu-val>false</emu-val>.</li><li>NOTE: No action is required.</li></ol></li><li>Set <var>lower</var> to <var>lower</var> + 1.</li></ol></li><li>Return <var>O</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore, it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.shift" type="built-in function">
<h1><span class="secnum">23.1.3.27</span> Array.prototype.shift ( )</h1>
<p>This method removes the first element of the array and returns it.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13070"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13071"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <var>len</var> = 0, then<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13072"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <emu-val>"length"</emu-val>, <emu-val>+0</emu-val><sub>𝔽</sub>, <emu-val>true</emu-val>).</li><li>Return <emu-val>undefined</emu-val>.</li></ol></li><li>Let <var>first</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13073"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <emu-val>"0"</emu-val>).</li><li>Let <var>k</var> be 1.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>from</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13074"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13075"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>to</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13076"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13077"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var> - 1)).</li><li>Let <var>fromPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13078"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>If <var>fromPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13079"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13080"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>to</var>, <var>fromValue</var>, <emu-val>true</emu-val>).</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_13081"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>fromPresent</var> is <emu-val>false</emu-val>.</li><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13082"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, <var>to</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13083"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13084"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13085"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var> - 1))).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13086"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_13087"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var> - 1), <emu-val>true</emu-val>).</li><li>Return <var>first</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.slice" type="built-in function">
<h1><span class="secnum">23.1.3.28</span> Array.prototype.slice ( <var>start</var>, <var>end</var> )</h1>
<p>This method returns an array containing the elements of the array from element <var>start</var> up to, but not including, element <var>end</var> (or through the end of the array if <var>end</var> is <emu-val>undefined</emu-val>). If <var>start</var> is negative, it is treated as <emu-eqn class="inline"><var>length</var> + <var>start</var></emu-eqn> where <var>length</var> is the length of the array. If <var>end</var> is negative, it is treated as <emu-eqn class="inline"><var>length</var> + <var>end</var></emu-eqn> where <var>length</var> is the length of the array.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13088"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13089"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13090"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>k</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>k</var> be <emu-xref aoid="max" id="_ref_13091"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>k</var> be <emu-xref aoid="min" id="_ref_13092"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>len</var>).</li><li>If <var>end</var> is <emu-val>undefined</emu-val>, let <var>relativeEnd</var> be <var>len</var>; else let <var>relativeEnd</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13093"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>end</var>).</li><li>If <var>relativeEnd</var> = -∞, let <var>final</var> be 0.</li><li>Else if <var>relativeEnd</var> &lt; 0, let <var>final</var> be <emu-xref aoid="max" id="_ref_13094"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeEnd</var>, 0).</li><li>Else, let <var>final</var> be <emu-xref aoid="min" id="_ref_13095"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeEnd</var>, <var>len</var>).</li><li>Let <var>count</var> be <emu-xref aoid="max" id="_ref_13096"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>final</var> - <var>k</var>, 0).</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_13097"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arrayspeciescreate" class="e-user-code">ArraySpeciesCreate</a></emu-xref>(<var>O</var>, <var>count</var>).</li><li>Let <var>n</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>final</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13098"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13099"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13100"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13101"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13102"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13103"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13104"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>n</var>)), <var>kValue</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li><li>Set <var>n</var> to <var>n</var> + 1.</li></ol></li><li id="step-array-proto-slice-set-length">Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13105"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_13106"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>n</var>), <emu-val>true</emu-val>).</li><li>Return <var>A</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>The explicit setting of the <emu-val>"length"</emu-val> property in step <emu-xref href="#step-array-proto-slice-set-length" id="_ref_719"><a href="indexed-collections.html#step-array-proto-slice-set-length">15</a></emu-xref> is intended to ensure the length is correct even when <var>A</var> is not a built-in Array.</p>
</div></emu-note>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.some" type="built-in function">
<h1><span class="secnum">23.1.3.29</span> Array.prototype.some ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p><var>callback</var> should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. <code>some</code> calls <var>callback</var> once for each element present in the array, in ascending order, until it finds one where <var>callback</var> returns <emu-val>true</emu-val>. If such an element is found, <code>some</code> immediately returns <emu-val>true</emu-val>. Otherwise, <code>some</code> returns <emu-val>false</emu-val>. <var>callback</var> is called only for elements of the array which actually exist; it is not called for missing elements of the array.</p>
<p>If a <var>thisArg</var> parameter is provided, it will be used as the <emu-val>this</emu-val> value for each invocation of <var>callback</var>. If it is not provided, <emu-val>undefined</emu-val> is used instead.</p>
<p><var>callback</var> is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p><code>some</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callback</var>.</p>
<p>The range of elements processed by <code>some</code> is set before the first call to <var>callback</var>. Elements that are appended to the array after the call to <code>some</code> begins will not be visited by <var>callback</var>. If existing elements of the array are changed, their value as passed to <var>callback</var> will be the value at the time that <code>some</code> visits them; elements that are deleted after the call to <code>some</code> begins and before being visited are not visited. <code>some</code> acts like the "exists" quantifier in mathematics. In particular, for an empty array, it returns <emu-val>false</emu-val>.</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13107"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13108"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13109"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13110"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13111"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13112"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13113"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>testResult</var> be <emu-xref aoid="ToBoolean" id="_ref_13114"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_13115"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13116"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»)).</li><li>If <var>testResult</var> is <emu-val>true</emu-val>, return <emu-val>true</emu-val>.</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.sort" oldids="sec-sortcompare" type="built-in function"><span id="sec-sortcompare"></span>
<h1><span class="secnum">23.1.3.30</span> Array.prototype.sort ( <var>comparator</var> )</h1>
<p>This method sorts the elements of this array. If <var>comparator</var> is not <emu-val>undefined</emu-val>, it should be a function that accepts two arguments <var>x</var> and <var>y</var> and returns a negative Number if <var>x</var> &lt; <var>y</var>, a positive Number if <var>x</var> &gt; <var>y</var>, or a zero otherwise.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li id="step-array-sort-comparefn">If <var>comparator</var> is not <emu-val>undefined</emu-val> and <emu-xref aoid="IsCallable" id="_ref_13117"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>comparator</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>obj</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13118"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li id="step-array-sort-len">Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13119"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>obj</var>).</li><li>Let <var>SortCompare</var> be a new <emu-xref href="#sec-abstract-closure" id="_ref_13120"><a href="ecmascript-data-types-and-values.html#sec-abstract-closure">Abstract Closure</a></emu-xref> with parameters (<var>x</var>, <var>y</var>) that captures <var>comparator</var> and performs the following steps when called:<ol><li>Return ?&nbsp;<emu-xref aoid="CompareArrayElements" id="_ref_13121"><a href="indexed-collections.html#sec-comparearrayelements">CompareArrayElements</a></emu-xref>(<var>x</var>, <var>y</var>, <var>comparator</var>).</li></ol></li><li id="step-array-sortindexedproperties">Let <var>sortedList</var> be ?&nbsp;<emu-xref aoid="SortIndexedProperties" id="_ref_13122"><a href="indexed-collections.html#sec-sortindexedproperties" class="e-user-code">SortIndexedProperties</a></emu-xref>(<var>obj</var>, <var>len</var>, <var>SortCompare</var>, <emu-const>skip-holes</emu-const>).</li><li>Let <var>itemCount</var> be the number of elements in <var>sortedList</var>.</li><li>Let <var>j</var> be 0.</li><li>Repeat, while <var>j</var> &lt; <var>itemCount</var>,<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13123"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>obj</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13124"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13125"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>j</var>)), <var>sortedList</var>[<var>j</var>], <emu-val>true</emu-val>).</li><li>Set <var>j</var> to <var>j</var> + 1.</li></ol></li><li>NOTE: The call to <emu-xref aoid="SortIndexedProperties" id="_ref_13126"><a href="indexed-collections.html#sec-sortindexedproperties">SortIndexedProperties</a></emu-xref> in step <emu-xref href="#step-array-sortindexedproperties" id="_ref_720"><a href="indexed-collections.html#step-array-sortindexedproperties">5</a></emu-xref> uses <emu-const>skip-holes</emu-const>. The remaining indices are deleted to preserve the number of holes that were detected and excluded from the sort.</li><li>Repeat, while <var>j</var> &lt; <var>len</var>,<ol><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13127"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>obj</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13128"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13129"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>j</var>))).</li><li>Set <var>j</var> to <var>j</var> + 1.</li></ol></li><li>Return <var>obj</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>Because non-existent property values always compare greater than <emu-val>undefined</emu-val> property values, and <emu-val>undefined</emu-val> always compares greater than any other value (see <emu-xref aoid="CompareArrayElements" id="_ref_13130"><a href="indexed-collections.html#sec-comparearrayelements">CompareArrayElements</a></emu-xref>), <emu-val>undefined</emu-val> property values always sort to the end of the result, followed by non-existent property values.</p>
</div></emu-note>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>Method calls performed by the <emu-xref aoid="ToString" id="_ref_13131"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref> <emu-xref href="#sec-algorithm-conventions-abstract-operations" id="_ref_13132"><a href="notational-conventions.html#sec-algorithm-conventions-abstract-operations">abstract operations</a></emu-xref> in steps <emu-xref href="#step-sortcompare-tostring-x" id="_ref_721"><a href="indexed-collections.html#step-sortcompare-tostring-x">5</a></emu-xref> and <emu-xref href="#step-sortcompare-tostring-y" id="_ref_722"><a href="indexed-collections.html#step-sortcompare-tostring-y">6</a></emu-xref> have the potential to cause <var>SortCompare</var> to not behave as a <emu-xref href="#consistent-comparator" id="_ref_13133"><a href="indexed-collections.html#consistent-comparator">consistent comparator</a></emu-xref>.</p>
</div></emu-note>
<emu-note><span class="note">Note 3</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore, it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
<emu-clause id="sec-sortindexedproperties" type="abstract operation" aoid="SortIndexedProperties">
<h1><span class="secnum">23.1.3.30.1</span> SortIndexedProperties ( <var>obj</var>, <var>len</var>, <var>SortCompare</var>, <var>holes</var> )</h1>
<p>The abstract operation SortIndexedProperties takes arguments <var>obj</var> (an Object), <var>len</var> (a non-negative <emu-xref href="#integer" id="_ref_13134"><a href="notational-conventions.html#integer">integer</a></emu-xref>), <var>SortCompare</var> (an <emu-xref href="#sec-abstract-closure" id="_ref_13135"><a href="ecmascript-data-types-and-values.html#sec-abstract-closure">Abstract Closure</a></emu-xref> with two parameters), and <var>holes</var> (<emu-const>skip-holes</emu-const> or <emu-const>read-through-holes</emu-const>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13136"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_13137"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-ecmascript-language-types" id="_ref_13138"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13139"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>items</var> be a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_13140"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13141"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13142"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>If <var>holes</var> is <emu-const>skip-holes</emu-const>, then<ol><li>Let <var>kRead</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13143"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>obj</var>, <var>Pk</var>).</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_13144"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>holes</var> is <emu-const>read-through-holes</emu-const>.</li><li>Let <var>kRead</var> be <emu-val>true</emu-val>.</li></ol></li><li>If <var>kRead</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13145"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>obj</var>, <var>Pk</var>).</li><li>Append <var>kValue</var> to <var>items</var>.</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li id="step-array-sort">Sort <var>items</var> using an <emu-xref href="#implementation-defined" id="_ref_13146"><a href="overview.html#implementation-defined">implementation-defined</a></emu-xref> sequence of <span class="e-user-code">calls to <var>SortCompare</var></span>. If any such call returns an <emu-xref href="#sec-completion-record-specification-type" id="_ref_13147"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">abrupt completion</a></emu-xref>, stop before performing any further calls to <var>SortCompare</var> and return that <emu-xref href="#sec-completion-record-specification-type" id="_ref_13148"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">Completion Record</a></emu-xref>.</li><li>Return <var>items</var>.</li></ol></emu-alg>
<p>The <dfn id="sort-order" tabindex="-1">sort order</dfn> is the ordering of <var>items</var> after completion of step <emu-xref href="#step-array-sort" id="_ref_723"><a href="indexed-collections.html#step-array-sort">4</a></emu-xref> of the algorithm above. The <emu-xref href="#sort-order" id="_ref_13149"><a href="indexed-collections.html#sort-order">sort order</a></emu-xref> is <emu-xref href="#implementation-defined" id="_ref_13150"><a href="overview.html#implementation-defined">implementation-defined</a></emu-xref> if <var>SortCompare</var> is not a <emu-xref href="#consistent-comparator" id="_ref_13151"><a href="indexed-collections.html#consistent-comparator">consistent comparator</a></emu-xref> for the elements of <var>items</var>. When SortIndexedProperties is invoked by <emu-xref href="#sec-array.prototype.sort" id="_ref_724"><a href="indexed-collections.html#sec-array.prototype.sort">Array.prototype.sort</a></emu-xref> or <emu-xref href="#sec-array.prototype.tosorted" id="_ref_725"><a href="indexed-collections.html#sec-array.prototype.tosorted">Array.prototype.toSorted</a></emu-xref>, the <emu-xref href="#sort-order" id="_ref_13152"><a href="indexed-collections.html#sort-order">sort order</a></emu-xref> is also <emu-xref href="#implementation-defined" id="_ref_13153"><a href="overview.html#implementation-defined">implementation-defined</a></emu-xref> if <var>comparator</var> is <emu-val>undefined</emu-val>, and all applications of <emu-xref aoid="ToString" id="_ref_13154"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>, to any specific value passed as an argument to <var>SortCompare</var>, do not produce the same result.</p>
<p>Unless the <emu-xref href="#sort-order" id="_ref_13155"><a href="indexed-collections.html#sort-order">sort order</a></emu-xref> is specified to be <emu-xref href="#implementation-defined" id="_ref_13156"><a href="overview.html#implementation-defined">implementation-defined</a></emu-xref>, it must satisfy all of the following conditions:</p>
<ul>
<li>
There must be some mathematical permutation π of the non-negative <emu-xref href="#integer" id="_ref_13157"><a href="notational-conventions.html#integer">integers</a></emu-xref> less than <var>itemCount</var>, such that for every non-negative <emu-xref href="#integer" id="_ref_13158"><a href="notational-conventions.html#integer">integer</a></emu-xref> <var>j</var> less than <var>itemCount</var>, the element <emu-eqn class="inline">old[<var>j</var>]</emu-eqn> is exactly the same as <emu-eqn class="inline">new[π(<var>j</var>)]</emu-eqn>.
</li>
<li>
Then for all non-negative <emu-xref href="#integer" id="_ref_13159"><a href="notational-conventions.html#integer">integers</a></emu-xref> <var>j</var> and <var>k</var>, each less than <var>itemCount</var>, if <emu-eqn class="inline"><emu-xref aoid="" id="_ref_13160"><a href="notational-conventions.html#%E2%84%9D"></a></emu-xref>(<var>SortCompare</var>(old[<var>j</var>], old[<var>k</var>])) &lt; 0</emu-eqn>, then <emu-eqn class="inline">π(<var>j</var>) &lt; π(<var>k</var>)</emu-eqn>.
</li>
<li>
And for all non-negative <emu-xref href="#integer" id="_ref_13161"><a href="notational-conventions.html#integer">integers</a></emu-xref> <var>j</var> and <var>k</var> such that <var>j</var> &lt; <var>k</var> &lt; <var>itemCount</var>, if <emu-eqn class="inline"><emu-xref aoid="" id="_ref_13162"><a href="notational-conventions.html#%E2%84%9D"></a></emu-xref>(<var>SortCompare</var>(old[<var>j</var>], old[<var>k</var>])) = 0</emu-eqn>, then <emu-eqn class="inline">π(<var>j</var>) &lt; π(<var>k</var>)</emu-eqn>; i.e., the sort is stable.
</li>
</ul>
<p>Here the notation <emu-eqn class="inline">old[<var>j</var>]</emu-eqn> is used to refer to <emu-eqn class="inline"><var>items</var>[<var>j</var>]</emu-eqn> before step <emu-xref href="#step-array-sort" id="_ref_726"><a href="indexed-collections.html#step-array-sort">4</a></emu-xref> is executed, and the notation <emu-eqn class="inline">new[<var>j</var>]</emu-eqn> to refer to <emu-eqn class="inline"><var>items</var>[<var>j</var>]</emu-eqn> after step <emu-xref href="#step-array-sort" id="_ref_727"><a href="indexed-collections.html#step-array-sort">4</a></emu-xref> has been executed.</p>
<p>An abstract closure or function <var>comparator</var> is a <dfn id="consistent-comparator" tabindex="-1">consistent comparator</dfn> for a set of values <var>S</var> if all of the requirements below are met for all values <var>a</var>, <var>b</var>, and <var>c</var> (possibly the same value) in the set <var>S</var>: The notation <emu-eqn class="inline"><var>a</var> &lt;<sub>C</sub> <var>b</var></emu-eqn> means <emu-eqn class="inline"><emu-xref aoid="" id="_ref_13163"><a href="notational-conventions.html#%E2%84%9D"></a></emu-xref>(<var>comparator</var>(<var>a</var>, <var>b</var>)) &lt; 0</emu-eqn>; <emu-eqn class="inline"><var>a</var> =<sub>C</sub> <var>b</var></emu-eqn> means <emu-eqn class="inline"><emu-xref aoid="" id="_ref_13164"><a href="notational-conventions.html#%E2%84%9D"></a></emu-xref>(<var>comparator</var>(<var>a</var>, <var>b</var>)) = 0</emu-eqn>; and <emu-eqn class="inline"><var>a</var> &gt;<sub>C</sub> <var>b</var></emu-eqn> means <emu-eqn class="inline"><emu-xref aoid="" id="_ref_13165"><a href="notational-conventions.html#%E2%84%9D"></a></emu-xref>(<var>comparator</var>(<var>a</var>, <var>b</var>)) &gt; 0</emu-eqn>.</p>
<ul>
<li>
Calling <var>comparator</var>(<var>a</var>, <var>b</var>) always returns the same value <var>v</var> when given a specific pair of values <var>a</var> and <var>b</var> as its two arguments. Furthermore, <var>v</var> <emu-xref href="#sec-ecmascript-language-types-number-type" id="_ref_13166"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-number-type">is a Number</a></emu-xref>, and <var>v</var> is not <emu-val>NaN</emu-val>. Note that this implies that exactly one of <var>a</var> &lt;<sub>C</sub> <var>b</var>, <var>a</var> =<sub>C</sub> <var>b</var>, and <var>a</var> &gt;<sub>C</sub> <var>b</var> will be true for a given pair of <var>a</var> and <var>b</var>.
</li>
<li>
Calling <var>comparator</var>(<var>a</var>, <var>b</var>) does not modify <var>obj</var> or any object on <var>obj</var>'s prototype chain.
</li>
<li>
<var>a</var> =<sub>C</sub> <var>a</var> (reflexivity)
</li>
<li>
If <var>a</var> =<sub>C</sub> <var>b</var>, then <var>b</var> =<sub>C</sub> <var>a</var> (symmetry)
</li>
<li>
If <var>a</var> =<sub>C</sub> <var>b</var> and <var>b</var> =<sub>C</sub> <var>c</var>, then <var>a</var> =<sub>C</sub> <var>c</var> (transitivity of =<sub>C</sub>)
</li>
<li>
If <var>a</var> &lt;<sub>C</sub> <var>b</var> and <var>b</var> &lt;<sub>C</sub> <var>c</var>, then <var>a</var> &lt;<sub>C</sub> <var>c</var> (transitivity of &lt;<sub>C</sub>)
</li>
<li>
If <var>a</var> &gt;<sub>C</sub> <var>b</var> and <var>b</var> &gt;<sub>C</sub> <var>c</var>, then <var>a</var> &gt;<sub>C</sub> <var>c</var> (transitivity of &gt;<sub>C</sub>)
</li>
</ul>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>The above conditions are necessary and sufficient to ensure that <var>comparator</var> divides the set <var>S</var> into equivalence classes and that these equivalence classes are totally ordered.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-comparearrayelements" type="abstract operation" aoid="CompareArrayElements">
<h1><span class="secnum">23.1.3.30.2</span> CompareArrayElements ( <var>x</var>, <var>y</var>, <var>comparator</var> )</h1>
<p>The abstract operation CompareArrayElements takes arguments <var>x</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_13167"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>), <var>y</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_13168"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>), and <var>comparator</var> (a <emu-xref href="#function-object" id="_ref_13169"><a href="ecmascript-data-types-and-values.html#function-object">function object</a></emu-xref> or <emu-val>undefined</emu-val>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13170"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a Number or an <emu-xref href="#sec-completion-record-specification-type" id="_ref_13171"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">abrupt completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>If <var>x</var> and <var>y</var> are both <emu-val>undefined</emu-val>, return <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>If <var>x</var> is <emu-val>undefined</emu-val>, return <emu-val>1</emu-val><sub>𝔽</sub>.</li><li>If <var>y</var> is <emu-val>undefined</emu-val>, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>comparator</var> is not <emu-val>undefined</emu-val>, then<ol><li>Let <var>v</var> be ?&nbsp;<emu-xref aoid="ToNumber" id="_ref_13172"><a href="abstract-operations.html#sec-tonumber" class="e-user-code">ToNumber</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_13173"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>comparator</var>, <emu-val>undefined</emu-val>, « <var>x</var>, <var>y</var>&nbsp;»)).</li><li>If <var>v</var> is <emu-val>NaN</emu-val>, return <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>Return <var>v</var>.</li></ol></li><li id="step-sortcompare-tostring-x">Let <var>xString</var> be ?&nbsp;<emu-xref aoid="ToString" id="_ref_13174"><a href="abstract-operations.html#sec-tostring" class="e-user-code">ToString</a></emu-xref>(<var>x</var>).</li><li id="step-sortcompare-tostring-y">Let <var>yString</var> be ?&nbsp;<emu-xref aoid="ToString" id="_ref_13175"><a href="abstract-operations.html#sec-tostring" class="e-user-code">ToString</a></emu-xref>(<var>y</var>).</li><li>Let <var>xSmaller</var> be !&nbsp;<emu-xref aoid="IsLessThan" id="_ref_13176"><a href="abstract-operations.html#sec-islessthan">IsLessThan</a></emu-xref>(<var>xString</var>, <var>yString</var>, <emu-val>true</emu-val>).</li><li>If <var>xSmaller</var> is <emu-val>true</emu-val>, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>Let <var>ySmaller</var> be !&nbsp;<emu-xref aoid="IsLessThan" id="_ref_13177"><a href="abstract-operations.html#sec-islessthan">IsLessThan</a></emu-xref>(<var>yString</var>, <var>xString</var>, <emu-val>true</emu-val>).</li><li>If <var>ySmaller</var> is <emu-val>true</emu-val>, return <emu-val>1</emu-val><sub>𝔽</sub>.</li><li>Return <emu-val>+0</emu-val><sub>𝔽</sub>.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-array.prototype.splice" type="built-in function">
<h1><span class="secnum">23.1.3.31</span> Array.prototype.splice ( <var>start</var>, <var>deleteCount</var>, ...<var>items</var> )</h1>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>This method deletes the <var>deleteCount</var> elements of the array starting at <emu-xref href="#integer-index" id="_ref_13178"><a href="ecmascript-data-types-and-values.html#integer-index">integer index</a></emu-xref> <var>start</var> and replaces them with the elements of <var>items</var>. It returns an Array containing the deleted elements (if any).</p>
</div></emu-note>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13179"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13180"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13181"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>actualStart</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>actualStart</var> be <emu-xref aoid="max" id="_ref_13182"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>actualStart</var> be <emu-xref aoid="min" id="_ref_13183"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>len</var>).</li><li>Let <var>itemCount</var> be the number of elements in <var>items</var>.</li><li>If <var>start</var> is not present, then<ol><li>Let <var>actualDeleteCount</var> be 0.</li></ol></li><li>Else if <var>deleteCount</var> is not present, then<ol><li>Let <var>actualDeleteCount</var> be <var>len</var> - <var>actualStart</var>.</li></ol></li><li>Else,<ol><li>Let <var>dc</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13184"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>deleteCount</var>).</li><li>Let <var>actualDeleteCount</var> be the result of <emu-xref href="#clamping" id="_ref_13185"><a href="notational-conventions.html#clamping">clamping</a></emu-xref> <var>dc</var> between 0 and <var>len</var> - <var>actualStart</var>.</li></ol></li><li>If <var>len</var> + <var>itemCount</var> - <var>actualDeleteCount</var> &gt; 2<sup>53</sup> - 1, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_13186"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arrayspeciescreate" class="e-user-code">ArraySpeciesCreate</a></emu-xref>(<var>O</var>, <var>actualDeleteCount</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>actualDeleteCount</var>,<ol><li>Let <var>from</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13187"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13188"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>actualStart</var> + <var>k</var>)).</li><li>If ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13189"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>from</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13190"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13191"><a href="abstract-operations.html#sec-createdatapropertyorthrow" class="e-user-code">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13192"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13193"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)), <var>fromValue</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li id="step-array-proto-splice-set-length">Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13194"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_13195"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>actualDeleteCount</var>), <emu-val>true</emu-val>).</li><li>If <var>itemCount</var> &lt; <var>actualDeleteCount</var>, then<ol><li>Set <var>k</var> to <var>actualStart</var>.</li><li>Repeat, while <var>k</var> &lt; (<var>len</var> - <var>actualDeleteCount</var>),<ol><li>Let <var>from</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13196"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13197"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var> + <var>actualDeleteCount</var>)).</li><li>Let <var>to</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13198"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13199"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var> + <var>itemCount</var>)).</li><li>If ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13200"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>from</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13201"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13202"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>to</var>, <var>fromValue</var>, <emu-val>true</emu-val>).</li></ol></li><li>Else,<ol><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13203"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, <var>to</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Set <var>k</var> to <var>len</var>.</li><li>Repeat, while <var>k</var> &gt; (<var>len</var> - <var>actualDeleteCount</var> + <var>itemCount</var>),<ol><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13204"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13205"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13206"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var> - 1))).</li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li></ol></li><li>Else if <var>itemCount</var> &gt; <var>actualDeleteCount</var>, then<ol><li>Set <var>k</var> to (<var>len</var> - <var>actualDeleteCount</var>).</li><li>Repeat, while <var>k</var> &gt; <var>actualStart</var>,<ol><li>Let <var>from</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13207"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13208"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var> + <var>actualDeleteCount</var> - 1)).</li><li>Let <var>to</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13209"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13210"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var> + <var>itemCount</var> - 1)).</li><li>If ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13211"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>from</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13212"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13213"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>to</var>, <var>fromValue</var>, <emu-val>true</emu-val>).</li></ol></li><li>Else,<ol><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13214"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, <var>to</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li></ol></li><li>Set <var>k</var> to <var>actualStart</var>.</li><li>For each element <var>E</var> of <var>items</var>, do<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13215"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13216"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13217"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)), <var>E</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li id="step-array-proto-splice-set-length-2">Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13218"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_13219"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var> - <var>actualDeleteCount</var> + <var>itemCount</var>), <emu-val>true</emu-val>).</li><li>Return <var>A</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>The explicit setting of the <emu-val>"length"</emu-val> property in steps <emu-xref href="#step-array-proto-splice-set-length" id="_ref_728"><a href="indexed-collections.html#step-array-proto-splice-set-length">15</a></emu-xref> and <emu-xref href="#step-array-proto-splice-set-length-2" id="_ref_729"><a href="indexed-collections.html#step-array-proto-splice-set-length-2">20</a></emu-xref> is intended to ensure the lengths are correct even when the objects are not built-in Arrays.</p>
</div></emu-note>
<emu-note><span class="note">Note 3</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.tolocalestring" type="built-in function">
<h1><span class="secnum">23.1.3.32</span> Array.prototype.toLocaleString ( [ <var>reserved1</var> [ , <var>reserved2</var> ] ] )</h1>
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.</p>
<emu-note><span class="note">Note 1</span><div class="note-contents">
<p>The first edition of ECMA-402 did not include a replacement specification for this method.</p>
</div></emu-note>
<p>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.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>array</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13220"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13221"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>array</var>).</li><li>Let <var>separator</var> be the <emu-xref href="#implementation-defined" id="_ref_13222"><a href="overview.html#implementation-defined">implementation-defined</a></emu-xref> list-separator String value appropriate for the <emu-xref href="#host-environment" id="_ref_13223"><a href="overview.html#host-environment">host environment</a></emu-xref>'s current locale (such as <emu-val>", "</emu-val>).</li><li>Let <var>R</var> be the empty String.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>If <var>k</var> &gt; 0, set <var>R</var> to the <emu-xref href="#string-concatenation" id="_ref_13224"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>R</var> and <var>separator</var>.</li><li>Let <var>element</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13225"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>array</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13226"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13227"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>))).</li><li>If <var>element</var> is neither <emu-val>undefined</emu-val> nor <emu-val>null</emu-val>, then<ol><li>Let <var>S</var> be ?&nbsp;<emu-xref aoid="ToString" id="_ref_13228"><a href="abstract-operations.html#sec-tostring" class="e-user-code">ToString</a></emu-xref>(? <emu-xref aoid="Invoke" id="_ref_13229"><a href="abstract-operations.html#sec-invoke" class="e-user-code">Invoke</a></emu-xref>(<var>element</var>, <emu-val>"toLocaleString"</emu-val>)).</li><li>Set <var>R</var> to the <emu-xref href="#string-concatenation" id="_ref_13230"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>R</var> and <var>S</var>.</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>R</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>This method converts the elements of the array to Strings using their <code>toLocaleString</code> methods, and then concatenates these Strings, separated by occurrences of an <emu-xref href="#implementation-defined" id="_ref_13231"><a href="overview.html#implementation-defined">implementation-defined</a></emu-xref> locale-sensitive separator String. This method is analogous to <code>toString</code> except that it is intended to yield a locale-sensitive result corresponding with conventions of the <emu-xref href="#host-environment" id="_ref_13232"><a href="overview.html#host-environment">host environment</a></emu-xref>'s current locale.</p>
</div></emu-note>
<emu-note><span class="note">Note 3</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.toreversed" type="built-in function">
<h1><span class="secnum">23.1.3.33</span> Array.prototype.toReversed ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13233"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13234"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_13235"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(<var>len</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>from</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13236"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13237"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var> - <var>k</var> - 1)).</li><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13238"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13239"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13240"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13241"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>fromValue</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.tosorted" type="built-in function">
<h1><span class="secnum">23.1.3.34</span> Array.prototype.toSorted ( <var>comparator</var> )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>If <var>comparator</var> is not <emu-val>undefined</emu-val> and <emu-xref aoid="IsCallable" id="_ref_13242"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>comparator</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13243"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13244"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_13245"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(<var>len</var>).</li><li>Let <var>SortCompare</var> be a new <emu-xref href="#sec-abstract-closure" id="_ref_13246"><a href="ecmascript-data-types-and-values.html#sec-abstract-closure">Abstract Closure</a></emu-xref> with parameters (<var>x</var>, <var>y</var>) that captures <var>comparator</var> and performs the following steps when called:<ol><li>Return ?&nbsp;<emu-xref aoid="CompareArrayElements" id="_ref_13247"><a href="indexed-collections.html#sec-comparearrayelements">CompareArrayElements</a></emu-xref>(<var>x</var>, <var>y</var>, <var>comparator</var>).</li></ol></li><li>Let <var>sortedList</var> be ?&nbsp;<emu-xref aoid="SortIndexedProperties" id="_ref_13248"><a href="indexed-collections.html#sec-sortindexedproperties" class="e-user-code">SortIndexedProperties</a></emu-xref>(<var>O</var>, <var>len</var>, <var>SortCompare</var>, <emu-const>read-through-holes</emu-const>).</li><li>Let <var>j</var> be 0.</li><li>Repeat, while <var>j</var> &lt; <var>len</var>,<ol><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13249"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13250"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13251"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>j</var>)), <var>sortedList</var>[<var>j</var>]).</li><li>Set <var>j</var> to <var>j</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.tospliced" type="built-in function">
<h1><span class="secnum">23.1.3.35</span> Array.prototype.toSpliced ( <var>start</var>, <var>skipCount</var>, ...<var>items</var> )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13252"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13253"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13254"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>actualStart</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>actualStart</var> be <emu-xref aoid="max" id="_ref_13255"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>actualStart</var> be <emu-xref aoid="min" id="_ref_13256"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>len</var>).</li><li>Let <var>insertCount</var> be the number of elements in <var>items</var>.</li><li>If <var>start</var> is not present, then<ol><li>Let <var>actualSkipCount</var> be 0.</li></ol></li><li>Else if <var>skipCount</var> is not present, then<ol><li>Let <var>actualSkipCount</var> be <var>len</var> - <var>actualStart</var>.</li></ol></li><li>Else,<ol><li>Let <var>sc</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13257"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>skipCount</var>).</li><li>Let <var>actualSkipCount</var> be the result of <emu-xref href="#clamping" id="_ref_13258"><a href="notational-conventions.html#clamping">clamping</a></emu-xref> <var>sc</var> between 0 and <var>len</var> - <var>actualStart</var>.</li></ol></li><li>Let <var>newLen</var> be <var>len</var> + <var>insertCount</var> - <var>actualSkipCount</var>.</li><li>If <var>newLen</var> &gt; 2<sup>53</sup> - 1, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_13259"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(<var>newLen</var>).</li><li>Let <var>i</var> be 0.</li><li>Let <var>r</var> be <var>actualStart</var> + <var>actualSkipCount</var>.</li><li>Repeat, while <var>i</var> &lt; <var>actualStart</var>,<ol><li>Let <var>Pi</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13260"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13261"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>i</var>)).</li><li>Let <var>iValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13262"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pi</var>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13263"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pi</var>, <var>iValue</var>).</li><li>Set <var>i</var> to <var>i</var> + 1.</li></ol></li><li>For each element <var>E</var> of <var>items</var>, do<ol><li>Let <var>Pi</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13264"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13265"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>i</var>)).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13266"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pi</var>, <var>E</var>).</li><li>Set <var>i</var> to <var>i</var> + 1.</li></ol></li><li>Repeat, while <var>i</var> &lt; <var>newLen</var>,<ol><li>Let <var>Pi</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13267"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13268"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>i</var>)).</li><li>Let <var>from</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13269"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13270"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>r</var>)).</li><li>Let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13271"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13272"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pi</var>, <var>fromValue</var>).</li><li>Set <var>i</var> to <var>i</var> + 1.</li><li>Set <var>r</var> to <var>r</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.tostring" type="built-in function">
<h1><span class="secnum">23.1.3.36</span> Array.prototype.toString ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>array</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13273"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>func</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13274"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>array</var>, <emu-val>"join"</emu-val>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13275"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>func</var>) is <emu-val>false</emu-val>, set <var>func</var> to the intrinsic function %Object.prototype.toString%.</li><li>Return ?&nbsp;<emu-xref aoid="Call" id="_ref_13276"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>func</var>, <var>array</var>).</li></ol></emu-alg>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.unshift" type="built-in function">
<h1><span class="secnum">23.1.3.37</span> Array.prototype.unshift ( ...<var>items</var> )</h1>
<p>This method prepends the arguments to the start of the array, such that their order within the array is the same as the order in which they appear in the argument list.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13277"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13278"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>argCount</var> be the number of elements in <var>items</var>.</li><li>If <var>argCount</var> &gt; 0, then<ol><li>If <var>len</var> + <var>argCount</var> &gt; 2<sup>53</sup> - 1, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be <var>len</var>.</li><li>Repeat, while <var>k</var> &gt; 0,<ol><li>Let <var>from</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13279"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13280"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var> - 1)).</li><li>Let <var>to</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13281"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13282"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var> + <var>argCount</var> - 1)).</li><li>Let <var>fromPresent</var> be ?&nbsp;<emu-xref aoid="HasProperty" id="_ref_13283"><a href="abstract-operations.html#sec-hasproperty" class="e-user-code">HasProperty</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>If <var>fromPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13284"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13285"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>to</var>, <var>fromValue</var>, <emu-val>true</emu-val>).</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_13286"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>fromPresent</var> is <emu-val>false</emu-val>.</li><li>Perform ?&nbsp;<emu-xref aoid="DeletePropertyOrThrow" id="_ref_13287"><a href="abstract-operations.html#sec-deletepropertyorthrow" class="e-user-code">DeletePropertyOrThrow</a></emu-xref>(<var>O</var>, <var>to</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li><li>Let <var>j</var> be <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>For each element <var>E</var> of <var>items</var>, do<ol><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13288"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13289"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<var>j</var>), <var>E</var>, <emu-val>true</emu-val>).</li><li>Set <var>j</var> to <var>j</var> + <emu-val>1</emu-val><sub>𝔽</sub>.</li></ol></li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13290"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <emu-val>"length"</emu-val>, <emu-xref aoid="𝔽" id="_ref_13291"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var> + <var>argCount</var>), <emu-val>true</emu-val>).</li><li>Return <emu-xref aoid="𝔽" id="_ref_13292"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var> + <var>argCount</var>).</li></ol></emu-alg>
<p>The <emu-val>"length"</emu-val> property of this method is <emu-val>1</emu-val><sub>𝔽</sub>.</p>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>This method is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-array.prototype.values" type="built-in function">
<h1><span class="secnum">23.1.3.38</span> Array.prototype.values ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13293"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Return <emu-xref aoid="CreateArrayIterator" id="_ref_13294"><a href="indexed-collections.html#sec-createarrayiterator">CreateArrayIterator</a></emu-xref>(<var>O</var>, <emu-const>value</emu-const>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-array.prototype.with" type="built-in function">
<h1><span class="secnum">23.1.3.39</span> Array.prototype.with ( <var>index</var>, <var>value</var> )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13295"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13296"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>Let <var>relativeIndex</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13297"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>index</var>).</li><li>If <var>relativeIndex</var> ≥ 0, let <var>actualIndex</var> be <var>relativeIndex</var>.</li><li>Else, let <var>actualIndex</var> be <var>len</var> + <var>relativeIndex</var>.</li><li>If <var>actualIndex</var><var>len</var> or <var>actualIndex</var> &lt; 0, throw a <emu-val>RangeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="ArrayCreate" id="_ref_13298"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arraycreate">ArrayCreate</a></emu-xref>(<var>len</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13299"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13300"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>If <var>k</var> = <var>actualIndex</var>, let <var>fromValue</var> be <var>value</var>.</li><li>Else, let <var>fromValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13301"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13302"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>fromValue</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause oldids="sec-array.prototype-@@iterator" id="sec-array.prototype-%symbol.iterator%" type="built-in function"><span id="sec-array.prototype-@@iterator"></span>
<h1><span class="secnum">23.1.3.40</span> Array.prototype [ %Symbol.iterator% ] ( )</h1>
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_13303"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref> property is %Array.prototype.values%, defined in <emu-xref href="#sec-array.prototype.values" id="_ref_730"><a href="indexed-collections.html#sec-array.prototype.values">23.1.3.38</a></emu-xref>.</p>
</emu-clause>
<emu-clause oldids="sec-array.prototype-@@unscopables" id="sec-array.prototype-%symbol.unscopables%"><span id="sec-array.prototype-@@unscopables"></span>
<h1><span class="secnum">23.1.3.41</span> Array.prototype [ %Symbol.unscopables% ]</h1>
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_13304"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.unscopables%</a></emu-xref> <emu-xref href="#sec-object-type" id="_ref_13305"><a href="ecmascript-data-types-and-values.html#sec-object-type">data property</a></emu-xref> is an object created by the following steps:</p>
<emu-alg><ol><li>Let <var>unscopableList</var> be <emu-xref aoid="OrdinaryObjectCreate" id="_ref_13306"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinaryobjectcreate">OrdinaryObjectCreate</a></emu-xref>(<emu-val>null</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13307"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"at"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13308"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"copyWithin"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13309"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"entries"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13310"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"fill"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13311"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"find"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13312"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"findIndex"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13313"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"findLast"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13314"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"findLastIndex"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13315"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"flat"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13316"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"flatMap"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13317"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"includes"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13318"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"keys"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13319"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"toReversed"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13320"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"toSorted"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13321"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"toSpliced"</emu-val>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_13322"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>unscopableList</var>, <emu-val>"values"</emu-val>, <emu-val>true</emu-val>).</li><li>Return <var>unscopableList</var>.</li></ol></emu-alg>
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>The own <emu-xref href="#property-name" id="_ref_13323"><a href="ecmascript-data-types-and-values.html#property-name">property names</a></emu-xref> of this object are <emu-xref href="#property-name" id="_ref_13324"><a href="ecmascript-data-types-and-values.html#property-name">property names</a></emu-xref> that were not included as standard properties of <code>Array.prototype</code> prior to the ECMAScript 2015 specification. These names are ignored for <code>with</code> 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 <code>with</code> statement whose binding object is an Array.</p>
<p>The reason that <emu-val>"with"</emu-val> is not included in the <var>unscopableList</var> is because it is already a <emu-xref href="#sec-keywords-and-reserved-words" id="_ref_731"><a href="ecmascript-language-lexical-grammar.html#sec-keywords-and-reserved-words">reserved word</a></emu-xref>.</p>
</div></emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-array-instances">
<h1><span class="secnum">23.1.4</span> Properties of Array Instances</h1>
<p>Array instances are <emu-xref href="#array-exotic-object" id="_ref_13325"><a href="ordinary-and-exotic-objects-behaviours.html#array-exotic-object">Array exotic objects</a></emu-xref> and have the internal methods specified for such objects. Array instances inherit properties from the <emu-xref href="#sec-properties-of-the-array-prototype-object" id="_ref_13326"><a href="indexed-collections.html#sec-properties-of-the-array-prototype-object">Array prototype object</a></emu-xref>.</p>
<p>Array instances have a <emu-val>"length"</emu-val> property, and a set of enumerable properties with <emu-xref href="#array-index" id="_ref_13327"><a href="ecmascript-data-types-and-values.html#array-index">array index</a></emu-xref> names.</p>
<emu-clause id="sec-properties-of-array-instances-length">
<h1><span class="secnum">23.1.4.1</span> length</h1>
<p>The <emu-val>"length"</emu-val> property of an Array instance is a <emu-xref href="#sec-object-type" id="_ref_13328"><a href="ecmascript-data-types-and-values.html#sec-object-type">data property</a></emu-xref> whose value is always numerically greater than the name of every configurable own property whose name is an <emu-xref href="#array-index" id="_ref_13329"><a href="ecmascript-data-types-and-values.html#array-index">array index</a></emu-xref>.</p>
<p>The <emu-val>"length"</emu-val> property initially has the attributes { <var class="field">[[Writable]]</var>: <emu-val>true</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>Reducing the value of the <emu-val>"length"</emu-val> property has the side-effect of deleting own array elements whose <emu-xref href="#array-index" id="_ref_13330"><a href="ecmascript-data-types-and-values.html#array-index">array index</a></emu-xref> is between the old and new length values. However, non-configurable properties can not be deleted. Attempting to set the <emu-val>"length"</emu-val> property of an Array to a value that is numerically less than or equal to the largest numeric own <emu-xref href="#property-name" id="_ref_13331"><a href="ecmascript-data-types-and-values.html#property-name">property name</a></emu-xref> of an existing non-configurable <emu-xref href="#array-index" id="_ref_732"><a href="ecmascript-data-types-and-values.html#array-index">array-indexed</a></emu-xref> 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 <emu-xref href="#property-name" id="_ref_13332"><a href="ecmascript-data-types-and-values.html#property-name">property name</a></emu-xref>. See <emu-xref href="#sec-array-exotic-objects-defineownproperty-p-desc" id="_ref_733"><a href="ordinary-and-exotic-objects-behaviours.html#sec-array-exotic-objects-defineownproperty-p-desc">10.4.2.1</a></emu-xref>.</p>
</div></emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-array-iterator-objects">
<h1><span class="secnum">23.1.5</span> Array Iterator Objects</h1>
<p>An <dfn variants="Array Iterators,Array Iterator object,Array Iterator objects" tabindex="-1">Array Iterator</dfn> is an object that represents a specific iteration over some specific Array instance object. There is not a named <emu-xref href="#constructor" id="_ref_13333"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> for Array Iterator objects. Instead, Array Iterator objects are created by calling certain methods of Array instance objects.</p>
<emu-clause id="sec-createarrayiterator" type="abstract operation" aoid="CreateArrayIterator">
<h1><span class="secnum">23.1.5.1</span> CreateArrayIterator ( <var>array</var>, <var>kind</var> )</h1>
<p>The abstract operation CreateArrayIterator takes arguments <var>array</var> (an Object) and <var>kind</var> (<emu-const>key+value</emu-const>, <emu-const>key</emu-const>, or <emu-const>value</emu-const>) and returns an Object. It is used to create <emu-xref href="#sec-iterator-interface" id="_ref_13334"><a href="control-abstraction-objects.html#sec-iterator-interface">iterator objects</a></emu-xref> for Array methods that return such <emu-xref href="#sec-iterator-interface" id="_ref_13335"><a href="control-abstraction-objects.html#sec-iterator-interface">iterators</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>iterator</var> be <emu-xref aoid="OrdinaryObjectCreate" id="_ref_13336"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinaryobjectcreate">OrdinaryObjectCreate</a></emu-xref>(<emu-xref href="#sec-%arrayiteratorprototype%-object" id="_ref_13337"><a href="indexed-collections.html#sec-%arrayiteratorprototype%-object">%ArrayIteratorPrototype%</a></emu-xref>, « <var class="field">[[IteratedArrayLike]]</var>, <var class="field">[[ArrayLikeNextIndex]]</var>, <var class="field">[[ArrayLikeIterationKind]]</var>&nbsp;»).</li><li>Set <var>iterator</var>.<var class="field">[[IteratedArrayLike]]</var> to <var>array</var>.</li><li>Set <var>iterator</var>.<var class="field">[[ArrayLikeNextIndex]]</var> to 0.</li><li>Set <var>iterator</var>.<var class="field">[[ArrayLikeIterationKind]]</var> to <var>kind</var>.</li><li>Return <var>iterator</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%arrayiteratorprototype%-object">
<h1><span class="secnum">23.1.5.2</span> The %ArrayIteratorPrototype% Object</h1>
<p>The <dfn tabindex="-1">%ArrayIteratorPrototype%</dfn> object:</p>
<ul>
<li>has properties that are inherited by all <emu-xref href="#sec-array-iterator-objects" id="_ref_13338"><a href="indexed-collections.html#sec-array-iterator-objects">Array Iterator objects</a></emu-xref>.</li>
<li>is an <emu-xref href="#ordinary-object" id="_ref_13339"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-%iterator.prototype%-object" id="_ref_13340"><a href="control-abstraction-objects.html#sec-%iterator.prototype%-object">%Iterator.prototype%</a></emu-xref>.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-%arrayiteratorprototype%.next" type="built-in function">
<h1><span class="secnum">23.1.5.2.1</span> %ArrayIteratorPrototype%.next ( )</h1>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>If <var>O</var> <emu-xref href="#sec-object-type" id="_ref_13341"><a href="ecmascript-data-types-and-values.html#sec-object-type">is not an Object</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <var>O</var> does not have all of the internal slots of an <emu-xref href="#sec-array-iterator-objects" id="_ref_13342"><a href="indexed-collections.html#sec-array-iterator-objects">Array Iterator</a></emu-xref> Instance (<emu-xref href="#sec-properties-of-array-iterator-instances" id="_ref_734"><a href="indexed-collections.html#sec-properties-of-array-iterator-instances">23.1.5.3</a></emu-xref>), throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>array</var> be <var>O</var>.<var class="field">[[IteratedArrayLike]]</var>.</li><li>If <var>array</var> is <emu-val>undefined</emu-val>, return <emu-xref aoid="CreateIteratorResultObject" id="_ref_13343"><a href="abstract-operations.html#sec-createiterresultobject">CreateIteratorResultObject</a></emu-xref>(<emu-val>undefined</emu-val>, <emu-val>true</emu-val>).</li><li>Let <var>index</var> be <var>O</var>.<var class="field">[[ArrayLikeNextIndex]]</var>.</li><li>Let <var>kind</var> be <var>O</var>.<var class="field">[[ArrayLikeIterationKind]]</var>.</li><li>If <var>array</var> has a <var class="field">[[TypedArrayName]]</var> internal slot, then<ol><li>Let <var>taRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13344"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>array</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13345"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13346"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li></ol></li><li>Else,<ol><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13347"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>array</var>).</li></ol></li><li>If <var>index</var><var>len</var>, then<ol><li>Set <var>O</var>.<var class="field">[[IteratedArrayLike]]</var> to <emu-val>undefined</emu-val>.</li><li>Return <emu-xref aoid="CreateIteratorResultObject" id="_ref_13348"><a href="abstract-operations.html#sec-createiterresultobject">CreateIteratorResultObject</a></emu-xref>(<emu-val>undefined</emu-val>, <emu-val>true</emu-val>).</li></ol></li><li>Set <var>O</var>.<var class="field">[[ArrayLikeNextIndex]]</var> to <var>index</var> + 1.</li><li>Let <var>indexNumber</var> be <emu-xref aoid="𝔽" id="_ref_13349"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>index</var>).</li><li>If <var>kind</var> is <emu-const>key</emu-const>, then<ol><li>Let <var>result</var> be <var>indexNumber</var>.</li></ol></li><li>Else,<ol><li>Let <var>elementKey</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13350"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<var>indexNumber</var>).</li><li>Let <var>elementValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13351"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>array</var>, <var>elementKey</var>).</li><li>If <var>kind</var> is <emu-const>value</emu-const>, then<ol><li>Let <var>result</var> be <var>elementValue</var>.</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_13352"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>kind</var> is <emu-const>key+value</emu-const>.</li><li>Let <var>result</var> be <emu-xref aoid="CreateArrayFromList" id="_ref_13353"><a href="abstract-operations.html#sec-createarrayfromlist">CreateArrayFromList</a></emu-xref><var>indexNumber</var>, <var>elementValue</var>&nbsp;»).</li></ol></li></ol></li><li>Return <emu-xref aoid="CreateIteratorResultObject" id="_ref_13354"><a href="abstract-operations.html#sec-createiterresultobject">CreateIteratorResultObject</a></emu-xref>(<var>result</var>, <emu-val>false</emu-val>).</li></ol></emu-alg>
</emu-clause>
<emu-clause oldids="sec-%arrayiteratorprototype%-@@tostringtag" id="sec-%arrayiteratorprototype%-%symbol.tostringtag%"><span id="sec-%arrayiteratorprototype%-@@tostringtag"></span>
<h1><span class="secnum">23.1.5.2.2</span> %ArrayIteratorPrototype% [ %Symbol.toStringTag% ]</h1>
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_13355"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.toStringTag%</a></emu-xref> property is the String value <emu-val>"Array Iterator"</emu-val>.</p>
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-array-iterator-instances">
<h1><span class="secnum">23.1.5.3</span> Properties of Array Iterator Instances</h1>
<p><emu-xref href="#sec-array-iterator-objects" id="_ref_13356"><a href="indexed-collections.html#sec-array-iterator-objects">Array Iterator</a></emu-xref> instances are <emu-xref href="#ordinary-object" id="_ref_13357"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary objects</a></emu-xref> that inherit properties from the <emu-xref href="#sec-%arrayiteratorprototype%-object" id="_ref_13358"><a href="indexed-collections.html#sec-%arrayiteratorprototype%-object">%ArrayIteratorPrototype%</a></emu-xref> intrinsic object. <emu-xref href="#sec-array-iterator-objects" id="_ref_13359"><a href="indexed-collections.html#sec-array-iterator-objects">Array Iterator</a></emu-xref> instances are initially created with the internal slots listed in <emu-xref href="#table-internal-slots-of-array-iterator-instances" id="_ref_735"><a href="indexed-collections.html#table-internal-slots-of-array-iterator-instances">Table 69</a></emu-xref>.</p>
<emu-table id="table-internal-slots-of-array-iterator-instances" caption="Internal Slots of Array Iterator Instances" oldids="table-48"><figure><figcaption>Table 69: Internal Slots of <emu-xref href="#sec-array-iterator-objects" id="_ref_13360"><a href="indexed-collections.html#sec-array-iterator-objects">Array Iterator</a></emu-xref> Instances</figcaption><span id="table-48"></span>
<table>
<tbody><tr>
<th>
Internal Slot
</th>
<th>
Type
</th>
<th>
Description
</th>
</tr>
<tr>
<td>
<var class="field">[[IteratedArrayLike]]</var>
</td>
<td>
an Object or <emu-val>undefined</emu-val>
</td>
<td>
The <emu-xref href="#sec-lengthofarraylike" id="_ref_13361"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref> that is being iterated.
</td>
</tr>
<tr>
<td>
<var class="field">[[ArrayLikeNextIndex]]</var>
</td>
<td>
a non-negative <emu-xref href="#integer" id="_ref_13362"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
<td>
The <emu-xref href="#integer-index" id="_ref_13363"><a href="ecmascript-data-types-and-values.html#integer-index">integer index</a></emu-xref> of the next element to be examined by this <emu-xref href="#sec-iterator-interface" id="_ref_13364"><a href="control-abstraction-objects.html#sec-iterator-interface">iterator</a></emu-xref>.
</td>
</tr>
<tr>
<td>
<var class="field">[[ArrayLikeIterationKind]]</var>
</td>
<td>
<emu-const>key+value</emu-const>, <emu-const>key</emu-const>, or <emu-const>value</emu-const>
</td>
<td>
A value that identifies what is returned for each element of the iteration.
</td>
</tr>
</tbody></table>
</figure></emu-table>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-typedarray-objects">
<h1><span class="secnum">23.2</span> TypedArray Objects</h1>
<p>A <var>TypedArray</var> presents an array-like view of an underlying binary data buffer (<emu-xref href="#sec-arraybuffer-objects" id="_ref_736"><a href="structured-data.html#sec-arraybuffer-objects">25.1</a></emu-xref>). A <dfn variants="TypedArray element types" tabindex="-1">TypedArray element type</dfn> is the underlying binary scalar data type that all elements of a <var>TypedArray</var> instance have. There is a distinct <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13365"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>, listed in <emu-xref href="#table-the-typedarray-constructors" id="_ref_737"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref>, for each of the supported element types. Each <emu-xref href="#constructor" id="_ref_13366"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> in <emu-xref href="#table-the-typedarray-constructors" id="_ref_738"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref> has a corresponding distinct prototype object.</p>
<emu-table id="table-the-typedarray-constructors" caption="The TypedArray Constructors" oldids="table-49"><figure><figcaption>Table 70: The <emu-xref href="#typedarray" id="_ref_13367"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> <emu-xref href="#constructor" id="_ref_13368"><a href="ecmascript-data-types-and-values.html#constructor">Constructors</a></emu-xref></figcaption><span id="table-49"></span>
<table>
<thead>
<tr>
<th>
<emu-xref href="#constructor" id="_ref_13369"><a href="ecmascript-data-types-and-values.html#constructor">Constructor</a></emu-xref> Name and Intrinsic
</th>
<th>
Element Type
</th>
<th>
Element Size
</th>
<th>
Conversion Operation
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody><tr>
<td>
Int8Array<br>
<dfn tabindex="-1">%Int8Array%</dfn>
</td>
<td>
<emu-const>int8</emu-const>
</td>
<td>
1
</td>
<td>
<emu-xref aoid="ToInt8" id="_ref_13370"><a href="abstract-operations.html#sec-toint8">ToInt8</a></emu-xref>
</td>
<td>
8-bit two's complement signed <emu-xref href="#integer" id="_ref_13371"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
</tr>
<tr>
<td>
Uint8Array<br>
<dfn tabindex="-1">%Uint8Array%</dfn>
</td>
<td>
<emu-const>uint8</emu-const>
</td>
<td>
1
</td>
<td>
<emu-xref aoid="ToUint8" id="_ref_13372"><a href="abstract-operations.html#sec-touint8">ToUint8</a></emu-xref>
</td>
<td>
8-bit unsigned <emu-xref href="#integer" id="_ref_13373"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
</tr>
<tr>
<td>
Uint8ClampedArray<br>
<dfn tabindex="-1">%Uint8ClampedArray%</dfn>
</td>
<td>
<emu-const>uint8clamped</emu-const>
</td>
<td>
1
</td>
<td>
<emu-xref aoid="ToUint8Clamp" id="_ref_13374"><a href="abstract-operations.html#sec-touint8clamp">ToUint8Clamp</a></emu-xref>
</td>
<td>
8-bit unsigned <emu-xref href="#integer" id="_ref_13375"><a href="notational-conventions.html#integer">integer</a></emu-xref> (clamped conversion)
</td>
</tr>
<tr>
<td>
Int16Array<br>
<dfn tabindex="-1">%Int16Array%</dfn>
</td>
<td>
<emu-const>int16</emu-const>
</td>
<td>
2
</td>
<td>
<emu-xref aoid="ToInt16" id="_ref_13376"><a href="abstract-operations.html#sec-toint16">ToInt16</a></emu-xref>
</td>
<td>
16-bit two's complement signed <emu-xref href="#integer" id="_ref_13377"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
</tr>
<tr>
<td>
Uint16Array<br>
<dfn tabindex="-1">%Uint16Array%</dfn>
</td>
<td>
<emu-const>uint16</emu-const>
</td>
<td>
2
</td>
<td>
<emu-xref aoid="ToUint16" id="_ref_13378"><a href="abstract-operations.html#sec-touint16">ToUint16</a></emu-xref>
</td>
<td>
16-bit unsigned <emu-xref href="#integer" id="_ref_13379"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
</tr>
<tr>
<td>
Int32Array<br>
<dfn tabindex="-1">%Int32Array%</dfn>
</td>
<td>
<emu-const>int32</emu-const>
</td>
<td>
4
</td>
<td>
<emu-xref aoid="ToInt32" id="_ref_13380"><a href="abstract-operations.html#sec-toint32">ToInt32</a></emu-xref>
</td>
<td>
32-bit two's complement signed <emu-xref href="#integer" id="_ref_13381"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
</tr>
<tr>
<td>
Uint32Array<br>
<dfn tabindex="-1">%Uint32Array%</dfn>
</td>
<td>
<emu-const>uint32</emu-const>
</td>
<td>
4
</td>
<td>
<emu-xref aoid="ToUint32" id="_ref_13382"><a href="abstract-operations.html#sec-touint32">ToUint32</a></emu-xref>
</td>
<td>
32-bit unsigned <emu-xref href="#integer" id="_ref_13383"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
</tr>
<tr>
<td>
BigInt64Array<br>
<dfn tabindex="-1">%BigInt64Array%</dfn>
</td>
<td>
<emu-const>bigint64</emu-const>
</td>
<td>
8
</td>
<td>
<emu-xref aoid="ToBigInt64" id="_ref_13384"><a href="abstract-operations.html#sec-tobigint64">ToBigInt64</a></emu-xref>
</td>
<td>
64-bit two's complement signed <emu-xref href="#integer" id="_ref_13385"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
</tr>
<tr>
<td>
BigUint64Array<br>
<dfn tabindex="-1">%BigUint64Array%</dfn>
</td>
<td>
<emu-const>biguint64</emu-const>
</td>
<td>
8
</td>
<td>
<emu-xref aoid="ToBigUint64" id="_ref_13386"><a href="abstract-operations.html#sec-tobiguint64">ToBigUint64</a></emu-xref>
</td>
<td>
64-bit unsigned <emu-xref href="#integer" id="_ref_13387"><a href="notational-conventions.html#integer">integer</a></emu-xref>
</td>
</tr>
<tr>
<td>
Float16Array<br>
<dfn tabindex="-1">%Float16Array%</dfn>
</td>
<td>
<emu-const>float16</emu-const>
</td>
<td>
2
</td>
<td>
</td>
<td>
16-bit IEEE floating point
</td>
</tr>
<tr>
<td>
Float32Array<br>
<dfn tabindex="-1">%Float32Array%</dfn>
</td>
<td>
<emu-const>float32</emu-const>
</td>
<td>
4
</td>
<td>
</td>
<td>
32-bit IEEE floating point
</td>
</tr>
<tr>
<td>
Float64Array<br>
<dfn tabindex="-1">%Float64Array%</dfn>
</td>
<td>
<emu-const>float64</emu-const>
</td>
<td>
8
</td>
<td>
</td>
<td>
64-bit IEEE floating point
</td>
</tr>
</tbody></table>
</figure></emu-table>
<p>In the definitions below, references to <var>TypedArray</var> should be replaced with the appropriate <emu-xref href="#constructor" id="_ref_13388"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> name from the above table.</p>
<emu-clause id="sec-%typedarray%-intrinsic-object">
<h1><span class="secnum">23.2.1</span> The %TypedArray% Intrinsic Object</h1>
<p>The <dfn tabindex="-1">%TypedArray%</dfn> intrinsic object:</p>
<ul>
<li>is a <emu-xref href="#constructor" id="_ref_13389"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> <emu-xref href="#function-object" id="_ref_13390"><a href="ecmascript-data-types-and-values.html#function-object">function object</a></emu-xref> that all of the <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13391"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> objects inherit from.</li>
<li>along with its corresponding prototype object, provides common properties that are inherited by all <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13392"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> and their instances.</li>
<li>does not have a global name or appear as a property of the <emu-xref href="#sec-global-object" id="_ref_13393"><a href="global-object.html#sec-global-object">global object</a></emu-xref>.</li>
<li>acts as the abstract superclass of the various <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13394"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref>.</li>
<li>will throw an error when invoked, because it is an abstract class <emu-xref href="#constructor" id="_ref_13395"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>. The <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13396"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> do not perform a <code>super</code> call to it.</li>
</ul>
<emu-clause id="sec-%typedarray%" type="built-in function">
<h1><span class="secnum">23.2.1.1</span> %TypedArray% ( )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg><ol><li>Throw a <emu-val>TypeError</emu-val> exception.</li></ol></emu-alg>
<p>The <emu-val>"length"</emu-val> property of this function is <emu-val>+0</emu-val><sub>𝔽</sub>.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-%typedarray%-intrinsic-object">
<h1><span class="secnum">23.2.2</span> Properties of the %TypedArray% Intrinsic Object</h1>
<p>The <emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13397"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref> intrinsic object:</p>
<ul>
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-function-prototype-object" id="_ref_13398"><a href="fundamental-objects.html#sec-properties-of-the-function-prototype-object">%Function.prototype%</a></emu-xref>.</li>
<li>has a <emu-val>"name"</emu-val> property whose value is <emu-val>"TypedArray"</emu-val>.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-%typedarray%.from" type="built-in function">
<h1><span class="secnum">23.2.2.1</span> %TypedArray%.from ( <var>source</var> [ , <var>mapper</var> [ , <var>thisArg</var> ] ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>C</var> be the <emu-val>this</emu-val> value.</li><li>If <emu-xref aoid="IsConstructor" id="_ref_13399"><a href="abstract-operations.html#sec-isconstructor">IsConstructor</a></emu-xref>(<var>C</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <var>mapper</var> is <emu-val>undefined</emu-val>, then<ol><li>Let <var>mapping</var> be <emu-val>false</emu-val>.</li></ol></li><li>Else,<ol><li>If <emu-xref aoid="IsCallable" id="_ref_13400"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>mapper</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>mapping</var> be <emu-val>true</emu-val>.</li></ol></li><li>Let <var>usingIterator</var> be ?&nbsp;<emu-xref aoid="GetMethod" id="_ref_13401"><a href="abstract-operations.html#sec-getmethod" class="e-user-code">GetMethod</a></emu-xref>(<var>source</var>, <emu-xref href="#sec-well-known-symbols" id="_ref_13402"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref>).</li><li>If <var>usingIterator</var> is not <emu-val>undefined</emu-val>, then<ol><li>Let <var>values</var> be ?&nbsp;<emu-xref aoid="IteratorToList" id="_ref_13403"><a href="abstract-operations.html#sec-iteratortolist" class="e-user-code">IteratorToList</a></emu-xref>(? <emu-xref aoid="GetIteratorFromMethod" id="_ref_13404"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>source</var>, <var>usingIterator</var>)).</li><li>Let <var>len</var> be the number of elements in <var>values</var>.</li><li>Let <var>targetObj</var> be ?&nbsp;<emu-xref aoid="TypedArrayCreateFromConstructor" id="_ref_13405"><a href="indexed-collections.html#sec-typedarraycreatefromconstructor" class="e-user-code">TypedArrayCreateFromConstructor</a></emu-xref>(<var>C</var>, « <emu-xref aoid="𝔽" id="_ref_13406"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>)&nbsp;»).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13407"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13408"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be the first element of <var>values</var>.</li><li>Remove the first element from <var>values</var>.</li><li>If <var>mapping</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>mappedValue</var> be ?&nbsp;<emu-xref aoid="Call" id="_ref_13409"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>mapper</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13410"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)&nbsp;»).</li></ol></li><li>Else,<ol><li>Let <var>mappedValue</var> be <var>kValue</var>.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13411"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>targetObj</var>, <var>Pk</var>, <var>mappedValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li><emu-xref href="#assert" id="_ref_13412"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>values</var> is now an empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_13413"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>Return <var>targetObj</var>.</li></ol></li><li>NOTE: <var>source</var> is not an <emu-xref href="#sec-iterable-interface" id="_ref_13414"><a href="control-abstraction-objects.html#sec-iterable-interface">iterable object</a></emu-xref>, so assume it is already an <emu-xref href="#sec-lengthofarraylike" id="_ref_13415"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref>.</li><li>Let <var>arrayLike</var> be !&nbsp;<emu-xref aoid="ToObject" id="_ref_13416"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<var>source</var>).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13417"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>arrayLike</var>).</li><li>Let <var>targetObj</var> be ?&nbsp;<emu-xref aoid="TypedArrayCreateFromConstructor" id="_ref_13418"><a href="indexed-collections.html#sec-typedarraycreatefromconstructor" class="e-user-code">TypedArrayCreateFromConstructor</a></emu-xref>(<var>C</var>, « <emu-xref aoid="𝔽" id="_ref_13419"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>)&nbsp;»).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13420"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13421"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13422"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>arrayLike</var>, <var>Pk</var>).</li><li>If <var>mapping</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>mappedValue</var> be ?&nbsp;<emu-xref aoid="Call" id="_ref_13423"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>mapper</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13424"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)&nbsp;»).</li></ol></li><li>Else,<ol><li>Let <var>mappedValue</var> be <var>kValue</var>.</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13425"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>targetObj</var>, <var>Pk</var>, <var>mappedValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>targetObj</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.of" type="built-in function">
<h1><span class="secnum">23.2.2.2</span> %TypedArray%.of ( ...<var>items</var> )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>len</var> be the number of elements in <var>items</var>.</li><li>Let <var>C</var> be the <emu-val>this</emu-val> value.</li><li>If <emu-xref aoid="IsConstructor" id="_ref_13426"><a href="abstract-operations.html#sec-isconstructor">IsConstructor</a></emu-xref>(<var>C</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>newObj</var> be ?&nbsp;<emu-xref aoid="TypedArrayCreateFromConstructor" id="_ref_13427"><a href="indexed-collections.html#sec-typedarraycreatefromconstructor" class="e-user-code">TypedArrayCreateFromConstructor</a></emu-xref>(<var>C</var>, « <emu-xref aoid="𝔽" id="_ref_13428"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>)&nbsp;»).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>kValue</var> be <var>items</var>[<var>k</var>].</li><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13429"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13430"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13431"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>newObj</var>, <var>Pk</var>, <var>kValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>newObj</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype">
<h1><span class="secnum">23.2.2.3</span> %TypedArray%.prototype</h1>
<p>The initial value of <emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13432"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>.prototype</code> is the <emu-xref href="#sec-properties-of-the-%typedarrayprototype%-object" id="_ref_13433"><a href="indexed-collections.html#sec-properties-of-the-%typedarrayprototype%-object">%TypedArray% prototype object</a></emu-xref>.</p>
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
</emu-clause>
<emu-clause oldids="sec-get-%typedarray%-@@species" id="sec-get-%typedarray%-%symbol.species%" type="built-in function"><span id="sec-get-%typedarray%-@@species"></span>
<h1><span class="secnum">23.2.2.4</span> get %TypedArray% [ %Symbol.species% ]</h1>
<p><emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13434"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>[%Symbol.species%]</code> is an <emu-xref href="#sec-object-type" id="_ref_13435"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
<emu-alg><ol><li>Return the <emu-val>this</emu-val> value.</li></ol></emu-alg>
<p>The value of the <emu-val>"name"</emu-val> property of this function is <emu-val>"get [Symbol.species]"</emu-val>.</p>
<emu-note><span class="note">Note</span><div class="note-contents">
<p><emu-xref href="#sec-properties-of-the-%typedarrayprototype%-object" id="_ref_13436"><a href="indexed-collections.html#sec-properties-of-the-%typedarrayprototype%-object">%TypedArray.prototype%</a></emu-xref> methods normally use their <emu-val>this</emu-val> value's <emu-xref href="#constructor" id="_ref_13437"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to create a derived object. However, a subclass <emu-xref href="#constructor" id="_ref_13438"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> may over-ride that default behaviour by redefining its <emu-xref href="#sec-well-known-symbols" id="_ref_13439"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.species%</a></emu-xref> property.</p>
</div></emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-%typedarrayprototype%-object">
<h1><span class="secnum">23.2.3</span> Properties of the %TypedArray% Prototype Object</h1>
<p>The <dfn tabindex="-1">%TypedArray% prototype object</dfn>:</p>
<ul>
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-object-prototype-object" id="_ref_13440"><a href="fundamental-objects.html#sec-properties-of-the-object-prototype-object">%Object.prototype%</a></emu-xref>.</li>
<li>is <dfn tabindex="-1">%TypedArray.prototype%</dfn>.</li>
<li>is an <emu-xref href="#ordinary-object" id="_ref_13441"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
<li>does not have a <var class="field">[[ViewedArrayBuffer]]</var> or any other of the internal slots that are specific to <var>TypedArray</var> instance objects.</li>
</ul>
<emu-clause id="sec-%typedarray%.prototype.at" type="built-in function">
<h1><span class="secnum">23.2.3.1</span> %TypedArray%.prototype.at ( <var>index</var> )</h1>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13442"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13443"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>relativeIndex</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13444"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>index</var>).</li><li>If <var>relativeIndex</var> ≥ 0, then<ol><li>Let <var>k</var> be <var>relativeIndex</var>.</li></ol></li><li>Else,<ol><li>Let <var>k</var> be <var>len</var> + <var>relativeIndex</var>.</li></ol></li><li>If <var>k</var> &lt; 0 or <var>k</var><var>len</var>, return <emu-val>undefined</emu-val>.</li><li>Return !&nbsp;<emu-xref aoid="Get" id="_ref_13445"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13446"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13447"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>))).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-get-%typedarray%.prototype.buffer" type="built-in function">
<h1><span class="secnum">23.2.3.2</span> get %TypedArray%.prototype.buffer</h1>
<p><emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13448"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>.prototype.buffer</code> is an <emu-xref href="#sec-object-type" id="_ref_13449"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="RequireInternalSlot" id="_ref_13450"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[TypedArrayName]]</var>).</li><li><emu-xref href="#assert" id="_ref_13451"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>O</var> has a <var class="field">[[ViewedArrayBuffer]]</var> internal slot.</li><li>Let <var>buffer</var> be <var>O</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Return <var>buffer</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-get-%typedarray%.prototype.bytelength" type="built-in function">
<h1><span class="secnum">23.2.3.3</span> get %TypedArray%.prototype.byteLength</h1>
<p><emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13452"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>.prototype.byteLength</code> is an <emu-xref href="#sec-object-type" id="_ref_13453"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="RequireInternalSlot" id="_ref_13454"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[TypedArrayName]]</var>).</li><li><emu-xref href="#assert" id="_ref_13455"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>O</var> has a <var class="field">[[ViewedArrayBuffer]]</var> internal slot.</li><li>Let <var>taRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13456"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13457"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, return <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>Let <var>size</var> be <emu-xref aoid="TypedArrayByteLength" id="_ref_13458"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraybytelength">TypedArrayByteLength</a></emu-xref>(<var>taRecord</var>).</li><li>Return <emu-xref aoid="𝔽" id="_ref_13459"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>size</var>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-get-%typedarray%.prototype.byteoffset" type="built-in function">
<h1><span class="secnum">23.2.3.4</span> get %TypedArray%.prototype.byteOffset</h1>
<p><emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13460"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>.prototype.byteOffset</code> is an <emu-xref href="#sec-object-type" id="_ref_13461"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="RequireInternalSlot" id="_ref_13462"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[TypedArrayName]]</var>).</li><li><emu-xref href="#assert" id="_ref_13463"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>O</var> has a <var class="field">[[ViewedArrayBuffer]]</var> internal slot.</li><li>Let <var>taRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13464"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13465"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, return <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>Let <var>offset</var> be <var>O</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Return <emu-xref aoid="𝔽" id="_ref_13466"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>offset</var>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.constructor">
<h1><span class="secnum">23.2.3.5</span> %TypedArray%.prototype.constructor</h1>
<p>The initial value of <emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13467"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>.prototype.constructor</code> is <emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13468"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref>.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.copywithin" type="built-in function">
<h1><span class="secnum">23.2.3.6</span> %TypedArray%.prototype.copyWithin ( <var>target</var>, <var>start</var> [ , <var>end</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.copyWithin</code> as defined in <emu-xref href="#sec-array.prototype.copywithin" id="_ref_739"><a href="indexed-collections.html#sec-array.prototype.copywithin">23.1.3.4</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13469"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13470"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>relativeTarget</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13471"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>target</var>).</li><li>If <var>relativeTarget</var> = -∞, let <var>targetIndex</var> be 0.</li><li>Else if <var>relativeTarget</var> &lt; 0, let <var>targetIndex</var> be <emu-xref aoid="max" id="_ref_13472"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeTarget</var>, 0).</li><li>Else, let <var>targetIndex</var> be <emu-xref aoid="min" id="_ref_13473"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeTarget</var>, <var>len</var>).</li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13474"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>startIndex</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>startIndex</var> be <emu-xref aoid="max" id="_ref_13475"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>startIndex</var> be <emu-xref aoid="min" id="_ref_13476"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>len</var>).</li><li>If <var>end</var> is <emu-val>undefined</emu-val>, let <var>relativeEnd</var> be <var>len</var>; else let <var>relativeEnd</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13477"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>end</var>).</li><li>If <var>relativeEnd</var> = -∞, let <var>endIndex</var> be 0.</li><li>Else if <var>relativeEnd</var> &lt; 0, let <var>endIndex</var> be <emu-xref aoid="max" id="_ref_13478"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeEnd</var>, 0).</li><li>Else, let <var>endIndex</var> be <emu-xref aoid="min" id="_ref_13479"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeEnd</var>, <var>len</var>).</li><li>Let <var>count</var> be <emu-xref aoid="min" id="_ref_13480"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>endIndex</var> - <var>startIndex</var>, <var>len</var> - <var>targetIndex</var>).</li><li>If <var>count</var> &gt; 0, then<ol><li>NOTE: The copying must be performed in a manner that preserves the bit-level encoding of the source data.</li><li>Let <var>buffer</var> be <var>O</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Set <var>taRecord</var> to <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13481"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13482"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Set <var>len</var> to <emu-xref aoid="TypedArrayLength" id="_ref_13483"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>NOTE: Side-effects of the above steps may have reduced the size of <var>O</var>, in which case copying should proceed with the longest still-applicable prefix.</li><li>Set <var>count</var> to <emu-xref aoid="min" id="_ref_13484"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>count</var>, <var>len</var> - <var>startIndex</var>, <var>len</var> - <var>targetIndex</var>).</li><li>Let <var>elementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13485"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>O</var>).</li><li>Let <var>byteOffset</var> be <var>O</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Let <var>toByteIndex</var> be (<var>targetIndex</var> × <var>elementSize</var>) + <var>byteOffset</var>.</li><li>Let <var>fromByteIndex</var> be (<var>startIndex</var> × <var>elementSize</var>) + <var>byteOffset</var>.</li><li>Let <var>countBytes</var> be <var>count</var> × <var>elementSize</var>.</li><li>If <var>fromByteIndex</var> &lt; <var>toByteIndex</var> and <var>toByteIndex</var> &lt; <var>fromByteIndex</var> + <var>countBytes</var>, then<ol><li>Let <var>direction</var> be -1.</li><li>Set <var>fromByteIndex</var> to <var>fromByteIndex</var> + <var>countBytes</var> - 1.</li><li>Set <var>toByteIndex</var> to <var>toByteIndex</var> + <var>countBytes</var> - 1.</li></ol></li><li>Else,<ol><li>Let <var>direction</var> be 1.</li></ol></li><li>Repeat, while <var>countBytes</var> &gt; 0,<ol><li>Let <var>value</var> be <emu-xref aoid="GetValueFromBuffer" id="_ref_13486"><a href="structured-data.html#sec-getvaluefrombuffer">GetValueFromBuffer</a></emu-xref>(<var>buffer</var>, <var>fromByteIndex</var>, <emu-const>uint8</emu-const>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Perform <emu-xref aoid="SetValueInBuffer" id="_ref_13487"><a href="structured-data.html#sec-setvalueinbuffer">SetValueInBuffer</a></emu-xref>(<var>buffer</var>, <var>toByteIndex</var>, <emu-const>uint8</emu-const>, <var>value</var>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Set <var>fromByteIndex</var> to <var>fromByteIndex</var> + <var>direction</var>.</li><li>Set <var>toByteIndex</var> to <var>toByteIndex</var> + <var>direction</var>.</li><li>Set <var>countBytes</var> to <var>countBytes</var> - 1.</li></ol></li></ol></li><li>Return <var>O</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.entries" type="built-in function">
<h1><span class="secnum">23.2.3.7</span> %TypedArray%.prototype.entries ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13488"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Return <emu-xref aoid="CreateArrayIterator" id="_ref_13489"><a href="indexed-collections.html#sec-createarrayiterator">CreateArrayIterator</a></emu-xref>(<var>O</var>, <emu-const>key+value</emu-const>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.every" type="built-in function">
<h1><span class="secnum">23.2.3.8</span> %TypedArray%.prototype.every ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.every</code> as defined in <emu-xref href="#sec-array.prototype.every" id="_ref_740"><a href="indexed-collections.html#sec-array.prototype.every">23.1.3.6</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13490"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13491"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13492"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13493"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13494"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13495"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>testResult</var> be <emu-xref aoid="ToBoolean" id="_ref_13496"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_13497"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13498"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»)).</li><li>If <var>testResult</var> is <emu-val>false</emu-val>, return <emu-val>false</emu-val>.</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>true</emu-val>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.fill" type="built-in function">
<h1><span class="secnum">23.2.3.9</span> %TypedArray%.prototype.fill ( <var>value</var> [ , <var>start</var> [ , <var>end</var> ] ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.fill</code> as defined in <emu-xref href="#sec-array.prototype.fill" id="_ref_741"><a href="indexed-collections.html#sec-array.prototype.fill">23.1.3.7</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13499"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13500"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <var>O</var>.<var class="field">[[ContentType]]</var> is <emu-const>bigint</emu-const>, set <var>value</var> to ?&nbsp;<emu-xref aoid="ToBigInt" id="_ref_13501"><a href="abstract-operations.html#sec-tobigint" class="e-user-code">ToBigInt</a></emu-xref>(<var>value</var>).</li><li>Else, set <var>value</var> to ?&nbsp;<emu-xref aoid="ToNumber" id="_ref_13502"><a href="abstract-operations.html#sec-tonumber" class="e-user-code">ToNumber</a></emu-xref>(<var>value</var>).</li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13503"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>startIndex</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>startIndex</var> be <emu-xref aoid="max" id="_ref_13504"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>startIndex</var> be <emu-xref aoid="min" id="_ref_13505"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>len</var>).</li><li>If <var>end</var> is <emu-val>undefined</emu-val>, let <var>relativeEnd</var> be <var>len</var>; else let <var>relativeEnd</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13506"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>end</var>).</li><li>If <var>relativeEnd</var> = -∞, let <var>endIndex</var> be 0.</li><li>Else if <var>relativeEnd</var> &lt; 0, let <var>endIndex</var> be <emu-xref aoid="max" id="_ref_13507"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>len</var> + <var>relativeEnd</var>, 0).</li><li>Else, let <var>endIndex</var> be <emu-xref aoid="min" id="_ref_13508"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeEnd</var>, <var>len</var>).</li><li>Set <var>taRecord</var> to <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13509"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13510"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Set <var>len</var> to <emu-xref aoid="TypedArrayLength" id="_ref_13511"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Set <var>endIndex</var> to <emu-xref aoid="min" id="_ref_13512"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>endIndex</var>, <var>len</var>).</li><li>Let <var>k</var> be <var>startIndex</var>.</li><li>Repeat, while <var>k</var> &lt; <var>endIndex</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13513"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13514"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13515"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>O</var>, <var>Pk</var>, <var>value</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>O</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.filter" type="built-in function">
<h1><span class="secnum">23.2.3.10</span> %TypedArray%.prototype.filter ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.filter</code> as defined in <emu-xref href="#sec-array.prototype.filter" id="_ref_742"><a href="indexed-collections.html#sec-array.prototype.filter">23.1.3.8</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13516"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13517"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13518"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>kept</var> be a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_13519"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>Let <var>captured</var> be 0.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13520"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13521"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13522"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>selected</var> be <emu-xref aoid="ToBoolean" id="_ref_13523"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_13524"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13525"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»)).</li><li>If <var>selected</var> is <emu-val>true</emu-val>, then<ol><li>Append <var>kValue</var> to <var>kept</var>.</li><li>Set <var>captured</var> to <var>captured</var> + 1.</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="TypedArraySpeciesCreate" id="_ref_13526"><a href="indexed-collections.html#typedarray-species-create" class="e-user-code">TypedArraySpeciesCreate</a></emu-xref>(<var>O</var>, « <emu-xref aoid="𝔽" id="_ref_13527"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>captured</var>)&nbsp;»).</li><li>Let <var>n</var> be 0.</li><li>For each element <var>e</var> of <var>kept</var>, do<ol><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13528"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13529"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13530"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>n</var>)), <var>e</var>, <emu-val>true</emu-val>).</li><li>Set <var>n</var> to <var>n</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.find" type="built-in function">
<h1><span class="secnum">23.2.3.11</span> %TypedArray%.prototype.find ( <var>predicate</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.find</code> as defined in <emu-xref href="#sec-array.prototype.find" id="_ref_743"><a href="indexed-collections.html#sec-array.prototype.find">23.1.3.9</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13531"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13532"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>findRec</var> be ?&nbsp;<emu-xref aoid="FindViaPredicate" id="_ref_13533"><a href="indexed-collections.html#sec-findviapredicate" class="e-user-code">FindViaPredicate</a></emu-xref>(<var>O</var>, <var>len</var>, <emu-const>ascending</emu-const>, <var>predicate</var>, <var>thisArg</var>).</li><li>Return <var>findRec</var>.<var class="field">[[Value]]</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.findindex" type="built-in function">
<h1><span class="secnum">23.2.3.12</span> %TypedArray%.prototype.findIndex ( <var>predicate</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.findIndex</code> as defined in <emu-xref href="#sec-array.prototype.findindex" id="_ref_744"><a href="indexed-collections.html#sec-array.prototype.findindex">23.1.3.10</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13534"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13535"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>findRec</var> be ?&nbsp;<emu-xref aoid="FindViaPredicate" id="_ref_13536"><a href="indexed-collections.html#sec-findviapredicate" class="e-user-code">FindViaPredicate</a></emu-xref>(<var>O</var>, <var>len</var>, <emu-const>ascending</emu-const>, <var>predicate</var>, <var>thisArg</var>).</li><li>Return <var>findRec</var>.<var class="field">[[Index]]</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.findlast" type="built-in function">
<h1><span class="secnum">23.2.3.13</span> %TypedArray%.prototype.findLast ( <var>predicate</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.findLast</code> as defined in <emu-xref href="#sec-array.prototype.findlast" id="_ref_745"><a href="indexed-collections.html#sec-array.prototype.findlast">23.1.3.11</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13537"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13538"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>findRec</var> be ?&nbsp;<emu-xref aoid="FindViaPredicate" id="_ref_13539"><a href="indexed-collections.html#sec-findviapredicate" class="e-user-code">FindViaPredicate</a></emu-xref>(<var>O</var>, <var>len</var>, <emu-const>descending</emu-const>, <var>predicate</var>, <var>thisArg</var>).</li><li>Return <var>findRec</var>.<var class="field">[[Value]]</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.findlastindex" type="built-in function">
<h1><span class="secnum">23.2.3.14</span> %TypedArray%.prototype.findLastIndex ( <var>predicate</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.findLastIndex</code> as defined in <emu-xref href="#sec-array.prototype.findlastindex" id="_ref_746"><a href="indexed-collections.html#sec-array.prototype.findlastindex">23.1.3.12</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13540"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13541"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>findRec</var> be ?&nbsp;<emu-xref aoid="FindViaPredicate" id="_ref_13542"><a href="indexed-collections.html#sec-findviapredicate" class="e-user-code">FindViaPredicate</a></emu-xref>(<var>O</var>, <var>len</var>, <emu-const>descending</emu-const>, <var>predicate</var>, <var>thisArg</var>).</li><li>Return <var>findRec</var>.<var class="field">[[Index]]</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.foreach" type="built-in function">
<h1><span class="secnum">23.2.3.15</span> %TypedArray%.prototype.forEach ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.forEach</code> as defined in <emu-xref href="#sec-array.prototype.foreach" id="_ref_747"><a href="indexed-collections.html#sec-array.prototype.foreach">23.1.3.15</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13543"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13544"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13545"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13546"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13547"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13548"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Call" id="_ref_13549"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13550"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.includes" type="built-in function">
<h1><span class="secnum">23.2.3.16</span> %TypedArray%.prototype.includes ( <var>searchElement</var> [ , <var>fromIndex</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.includes</code> as defined in <emu-xref href="#sec-array.prototype.includes" id="_ref_748"><a href="indexed-collections.html#sec-array.prototype.includes">23.1.3.16</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13551"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13552"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <var>len</var> = 0, return <emu-val>false</emu-val>.</li><li>Let <var>n</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13553"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>fromIndex</var>).</li><li><emu-xref href="#assert" id="_ref_13554"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: If <var>fromIndex</var> is <emu-val>undefined</emu-val>, then <var>n</var> is 0.</li><li>If <var>n</var> = +∞, return <emu-val>false</emu-val>.</li><li>If <var>n</var> = -∞, set <var>n</var> to 0.</li><li>If <var>n</var> ≥ 0, then<ol><li>Let <var>k</var> be <var>n</var>.</li></ol></li><li>Else,<ol><li>Let <var>k</var> be <var>len</var> + <var>n</var>.</li><li>If <var>k</var> &lt; 0, set <var>k</var> to 0.</li></ol></li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>elementK</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13555"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13556"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13557"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>))).</li><li>If <emu-xref aoid="SameValueZero" id="_ref_13558"><a href="abstract-operations.html#sec-samevaluezero">SameValueZero</a></emu-xref>(<var>searchElement</var>, <var>elementK</var>) is <emu-val>true</emu-val>, return <emu-val>true</emu-val>.</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.indexof" type="built-in function">
<h1><span class="secnum">23.2.3.17</span> %TypedArray%.prototype.indexOf ( <var>searchElement</var> [ , <var>fromIndex</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.indexOf</code> as defined in <emu-xref href="#sec-array.prototype.indexof" id="_ref_749"><a href="indexed-collections.html#sec-array.prototype.indexof">23.1.3.17</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13559"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13560"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <var>len</var> = 0, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>Let <var>n</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13561"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>fromIndex</var>).</li><li><emu-xref href="#assert" id="_ref_13562"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: If <var>fromIndex</var> is <emu-val>undefined</emu-val>, then <var>n</var> is 0.</li><li>If <var>n</var> = +∞, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>n</var> = -∞, set <var>n</var> to 0.</li><li>If <var>n</var> ≥ 0, then<ol><li>Let <var>k</var> be <var>n</var>.</li></ol></li><li>Else,<ol><li>Let <var>k</var> be <var>len</var> + <var>n</var>.</li><li>If <var>k</var> &lt; 0, set <var>k</var> to 0.</li></ol></li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13563"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13564"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be !&nbsp;<emu-xref aoid="HasProperty" id="_ref_13565"><a href="abstract-operations.html#sec-hasproperty">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>elementK</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13566"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <emu-xref aoid="IsStrictlyEqual" id="_ref_13567"><a href="abstract-operations.html#sec-isstrictlyequal">IsStrictlyEqual</a></emu-xref>(<var>searchElement</var>, <var>elementK</var>) is <emu-val>true</emu-val>, return <emu-xref aoid="𝔽" id="_ref_13568"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>-1</emu-val><sub>𝔽</sub>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.join" type="built-in function">
<h1><span class="secnum">23.2.3.18</span> %TypedArray%.prototype.join ( <var>separator</var> )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.join</code> as defined in <emu-xref href="#sec-array.prototype.join" id="_ref_750"><a href="indexed-collections.html#sec-array.prototype.join">23.1.3.18</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13569"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13570"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <var>separator</var> is <emu-val>undefined</emu-val>, let <var>sep</var> be <emu-val>","</emu-val>.</li><li>Else, let <var>sep</var> be ?&nbsp;<emu-xref aoid="ToString" id="_ref_13571"><a href="abstract-operations.html#sec-tostring" class="e-user-code">ToString</a></emu-xref>(<var>separator</var>).</li><li>Let <var>R</var> be the empty String.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>If <var>k</var> &gt; 0, set <var>R</var> to the <emu-xref href="#string-concatenation" id="_ref_13572"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>R</var> and <var>sep</var>.</li><li>Let <var>element</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13573"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13574"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13575"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>))).</li><li>If <var>element</var> is not <emu-val>undefined</emu-val>, then<ol><li>Let <var>S</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13576"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<var>element</var>).</li><li>Set <var>R</var> to the <emu-xref href="#string-concatenation" id="_ref_13577"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>R</var> and <var>S</var>.</li></ol></li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>R</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.keys" type="built-in function">
<h1><span class="secnum">23.2.3.19</span> %TypedArray%.prototype.keys ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13578"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Return <emu-xref aoid="CreateArrayIterator" id="_ref_13579"><a href="indexed-collections.html#sec-createarrayiterator">CreateArrayIterator</a></emu-xref>(<var>O</var>, <emu-const>key</emu-const>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.lastindexof" type="built-in function">
<h1><span class="secnum">23.2.3.20</span> %TypedArray%.prototype.lastIndexOf ( <var>searchElement</var> [ , <var>fromIndex</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.lastIndexOf</code> as defined in <emu-xref href="#sec-array.prototype.lastindexof" id="_ref_751"><a href="indexed-collections.html#sec-array.prototype.lastindexof">23.1.3.20</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13580"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13581"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <var>len</var> = 0, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>fromIndex</var> is present, let <var>n</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13582"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>fromIndex</var>); else let <var>n</var> be <var>len</var> - 1.</li><li>If <var>n</var> = -∞, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>n</var> ≥ 0, then<ol><li>Let <var>k</var> be <emu-xref aoid="min" id="_ref_13583"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>n</var>, <var>len</var> - 1).</li></ol></li><li>Else,<ol><li>Let <var>k</var> be <var>len</var> + <var>n</var>.</li></ol></li><li>Repeat, while <var>k</var> ≥ 0,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13584"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13585"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kPresent</var> be !&nbsp;<emu-xref aoid="HasProperty" id="_ref_13586"><a href="abstract-operations.html#sec-hasproperty">HasProperty</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <var>kPresent</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>elementK</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13587"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>If <emu-xref aoid="IsStrictlyEqual" id="_ref_13588"><a href="abstract-operations.html#sec-isstrictlyequal">IsStrictlyEqual</a></emu-xref>(<var>searchElement</var>, <var>elementK</var>) is <emu-val>true</emu-val>, return <emu-xref aoid="𝔽" id="_ref_13589"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>).</li></ol></li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li><li>Return <emu-val>-1</emu-val><sub>𝔽</sub>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-get-%typedarray%.prototype.length" type="built-in function">
<h1><span class="secnum">23.2.3.21</span> get %TypedArray%.prototype.length</h1>
<p><emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13590"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>.prototype.length</code> is an <emu-xref href="#sec-object-type" id="_ref_13591"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="RequireInternalSlot" id="_ref_13592"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[TypedArrayName]]</var>).</li><li><emu-xref href="#assert" id="_ref_13593"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>O</var> has <var class="field">[[ViewedArrayBuffer]]</var> and <var class="field">[[ArrayLength]]</var> internal slots.</li><li>Let <var>taRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13594"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13595"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, return <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>Let <var>length</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13596"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Return <emu-xref aoid="𝔽" id="_ref_13597"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>length</var>).</li></ol></emu-alg>
<p>This function is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.map" type="built-in function">
<h1><span class="secnum">23.2.3.22</span> %TypedArray%.prototype.map ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.map</code> as defined in <emu-xref href="#sec-array.prototype.map" id="_ref_752"><a href="indexed-collections.html#sec-array.prototype.map">23.1.3.21</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13598"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13599"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13600"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="TypedArraySpeciesCreate" id="_ref_13601"><a href="indexed-collections.html#typedarray-species-create" class="e-user-code">TypedArraySpeciesCreate</a></emu-xref>(<var>O</var>, « <emu-xref aoid="𝔽" id="_ref_13602"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var>)&nbsp;»).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13603"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13604"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13605"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>mappedValue</var> be ?&nbsp;<emu-xref aoid="Call" id="_ref_13606"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13607"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13608"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>mappedValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.reduce" type="built-in function">
<h1><span class="secnum">23.2.3.23</span> %TypedArray%.prototype.reduce ( <var>callback</var> [ , <var>initialValue</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.reduce</code> as defined in <emu-xref href="#sec-array.prototype.reduce" id="_ref_753"><a href="indexed-collections.html#sec-array.prototype.reduce">23.1.3.24</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13609"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13610"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13611"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <var>len</var> = 0 and <var>initialValue</var> is not present, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Let <var>accumulator</var> be <emu-val>undefined</emu-val>.</li><li>If <var>initialValue</var> is present, then<ol><li>Set <var>accumulator</var> to <var>initialValue</var>.</li></ol></li><li>Else,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13612"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13613"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Set <var>accumulator</var> to !&nbsp;<emu-xref aoid="Get" id="_ref_13614"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13615"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13616"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13617"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Set <var>accumulator</var> to ?&nbsp;<emu-xref aoid="Call" id="_ref_13618"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <emu-val>undefined</emu-val>, « <var>accumulator</var>, <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13619"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>accumulator</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.reduceright" type="built-in function">
<h1><span class="secnum">23.2.3.24</span> %TypedArray%.prototype.reduceRight ( <var>callback</var> [ , <var>initialValue</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.reduceRight</code> as defined in <emu-xref href="#sec-array.prototype.reduceright" id="_ref_754"><a href="indexed-collections.html#sec-array.prototype.reduceright">23.1.3.25</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13620"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13621"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13622"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <var>len</var> = 0 and <var>initialValue</var> is not present, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be <var>len</var> - 1.</li><li>Let <var>accumulator</var> be <emu-val>undefined</emu-val>.</li><li>If <var>initialValue</var> is present, then<ol><li>Set <var>accumulator</var> to <var>initialValue</var>.</li></ol></li><li>Else,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13623"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13624"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Set <var>accumulator</var> to !&nbsp;<emu-xref aoid="Get" id="_ref_13625"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li><li>Repeat, while <var>k</var> ≥ 0,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13626"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13627"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13628"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Set <var>accumulator</var> to ?&nbsp;<emu-xref aoid="Call" id="_ref_13629"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <emu-val>undefined</emu-val>, « <var>accumulator</var>, <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13630"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»).</li><li>Set <var>k</var> to <var>k</var> - 1.</li></ol></li><li>Return <var>accumulator</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.reverse" type="built-in function">
<h1><span class="secnum">23.2.3.25</span> %TypedArray%.prototype.reverse ( )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.reverse</code> as defined in <emu-xref href="#sec-array.prototype.reverse" id="_ref_755"><a href="indexed-collections.html#sec-array.prototype.reverse">23.1.3.26</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13631"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13632"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>middle</var> be <emu-xref aoid="floor" id="_ref_13633"><a href="notational-conventions.html#eqn-floor">floor</a></emu-xref>(<var>len</var> / 2).</li><li>Let <var>lower</var> be 0.</li><li>Repeat, while <var>lower</var><var>middle</var>,<ol><li>Let <var>upper</var> be <var>len</var> - <var>lower</var> - 1.</li><li>Let <var>upperP</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13634"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13635"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>upper</var>)).</li><li>Let <var>lowerP</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13636"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13637"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>lower</var>)).</li><li>Let <var>lowerValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13638"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>lowerP</var>).</li><li>Let <var>upperValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13639"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>upperP</var>).</li><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13640"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>O</var>, <var>lowerP</var>, <var>upperValue</var>, <emu-val>true</emu-val>).</li><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13641"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>O</var>, <var>upperP</var>, <var>lowerValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>lower</var> to <var>lower</var> + 1.</li></ol></li><li>Return <var>O</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.set" oldids="sec-%typedarray%.prototype.set-overloaded-offset" type="built-in function"><span id="sec-%typedarray%.prototype.set-overloaded-offset"></span>
<h1><span class="secnum">23.2.3.26</span> %TypedArray%.prototype.set ( <var>source</var> [ , <var>offset</var> ] )</h1>
<p>This method sets multiple values in this <var>TypedArray</var>, reading the values from <var>source</var>. The details differ based upon the type of <var>source</var>. The optional <var>offset</var> value indicates the first element index in this <var>TypedArray</var> where values are written. If omitted, it is assumed to be 0.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>target</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="RequireInternalSlot" id="_ref_13642"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>target</var>, <var class="field">[[TypedArrayName]]</var>).</li><li><emu-xref href="#assert" id="_ref_13643"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>target</var> has a <var class="field">[[ViewedArrayBuffer]]</var> internal slot.</li><li>Let <var>targetOffset</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13644"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>offset</var>).</li><li>If <var>targetOffset</var> &lt; 0, throw a <emu-val>RangeError</emu-val> exception.</li><li>If <var>source</var> <emu-xref href="#sec-object-type" id="_ref_13645"><a href="ecmascript-data-types-and-values.html#sec-object-type">is an Object</a></emu-xref> that has a <var class="field">[[TypedArrayName]]</var> internal slot, then<ol><li>Perform ?&nbsp;<emu-xref aoid="SetTypedArrayFromTypedArray" id="_ref_13646"><a href="indexed-collections.html#sec-settypedarrayfromtypedarray">SetTypedArrayFromTypedArray</a></emu-xref>(<var>target</var>, <var>targetOffset</var>, <var>source</var>).</li></ol></li><li>Else,<ol><li>Perform ?&nbsp;<emu-xref aoid="SetTypedArrayFromArrayLike" id="_ref_13647"><a href="indexed-collections.html#sec-settypedarrayfromarraylike" class="e-user-code">SetTypedArrayFromArrayLike</a></emu-xref>(<var>target</var>, <var>targetOffset</var>, <var>source</var>).</li></ol></li><li>Return <emu-val>undefined</emu-val>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
<emu-clause id="sec-settypedarrayfromarraylike" type="abstract operation" oldids="sec-%typedarray%.prototype.set-array-offset" aoid="SetTypedArrayFromArrayLike"><span id="sec-%typedarray%.prototype.set-array-offset"></span>
<h1><span class="secnum">23.2.3.26.1</span> SetTypedArrayFromArrayLike ( <var>target</var>, <var>targetOffset</var>, <var>source</var> )</h1>
<p>The abstract operation SetTypedArrayFromArrayLike takes arguments <var>target</var> (a <emu-xref href="#typedarray" id="_ref_13648"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>), <var>targetOffset</var> (a non-negative <emu-xref href="#integer" id="_ref_13649"><a href="notational-conventions.html#integer">integer</a></emu-xref> or +∞), and <var>source</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_13650"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>, but not a <emu-xref href="#typedarray" id="_ref_13651"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13652"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> <emu-const>unused</emu-const> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13653"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It sets multiple values in <var>target</var>, starting at index <var>targetOffset</var>, reading the values from <var>source</var>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>targetRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13654"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>target</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13655"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>targetRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>targetLength</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13656"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>targetRecord</var>).</li><li>Let <var>src</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_13657"><a href="abstract-operations.html#sec-toobject">ToObject</a></emu-xref>(<var>source</var>).</li><li>Let <var>srcLength</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13658"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>src</var>).</li><li>If <var>targetOffset</var> = +∞, throw a <emu-val>RangeError</emu-val> exception.</li><li>If <var>srcLength</var> + <var>targetOffset</var> &gt; <var>targetLength</var>, throw a <emu-val>RangeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>srcLength</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13659"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13660"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>value</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13661"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>src</var>, <var>Pk</var>).</li><li>Let <var>targetIndex</var> be <emu-xref aoid="𝔽" id="_ref_13662"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>targetOffset</var> + <var>k</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="TypedArraySetElement" id="_ref_13663"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraysetelement" class="e-user-code">TypedArraySetElement</a></emu-xref>(<var>target</var>, <var>targetIndex</var>, <var>value</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-settypedarrayfromtypedarray" type="abstract operation" oldids="sec-%typedarray%.prototype.set-typedarray-offset" aoid="SetTypedArrayFromTypedArray"><span id="sec-%typedarray%.prototype.set-typedarray-offset"></span>
<h1><span class="secnum">23.2.3.26.2</span> SetTypedArrayFromTypedArray ( <var>target</var>, <var>targetOffset</var>, <var>source</var> )</h1>
<p>The abstract operation SetTypedArrayFromTypedArray takes arguments <var>target</var> (a <emu-xref href="#typedarray" id="_ref_13664"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>), <var>targetOffset</var> (a non-negative <emu-xref href="#integer" id="_ref_13665"><a href="notational-conventions.html#integer">integer</a></emu-xref> or +∞), and <var>source</var> (a <emu-xref href="#typedarray" id="_ref_13666"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13667"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> <emu-const>unused</emu-const> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13668"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It sets multiple values in <var>target</var>, starting at index <var>targetOffset</var>, reading the values from <var>source</var>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>targetBuffer</var> be <var>target</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Let <var>targetRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13669"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>target</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13670"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>targetRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>targetLength</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13671"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>targetRecord</var>).</li><li>Let <var>srcBuffer</var> be <var>source</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Let <var>srcRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13672"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>source</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13673"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>srcRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>srcLength</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13674"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>srcRecord</var>).</li><li>Let <var>targetType</var> be <emu-xref aoid="TypedArrayElementType" id="_ref_13675"><a href="indexed-collections.html#sec-typedarrayelementtype">TypedArrayElementType</a></emu-xref>(<var>target</var>).</li><li>Let <var>targetElementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13676"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>target</var>).</li><li>Let <var>targetByteOffset</var> be <var>target</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Let <var>srcType</var> be <emu-xref aoid="TypedArrayElementType" id="_ref_13677"><a href="indexed-collections.html#sec-typedarrayelementtype">TypedArrayElementType</a></emu-xref>(<var>source</var>).</li><li>Let <var>srcElementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13678"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>source</var>).</li><li>Let <var>srcByteOffset</var> be <var>source</var>.<var class="field">[[ByteOffset]]</var>.</li><li>If <var>targetOffset</var> = +∞, throw a <emu-val>RangeError</emu-val> exception.</li><li>If <var>srcLength</var> + <var>targetOffset</var> &gt; <var>targetLength</var>, throw a <emu-val>RangeError</emu-val> exception.</li><li>If <var>target</var>.<var class="field">[[ContentType]]</var> is not <var>source</var>.<var class="field">[[ContentType]]</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <emu-xref aoid="IsSharedArrayBuffer" id="_ref_13679"><a href="structured-data.html#sec-issharedarraybuffer">IsSharedArrayBuffer</a></emu-xref>(<var>srcBuffer</var>) is <emu-val>true</emu-val>, <emu-xref aoid="IsSharedArrayBuffer" id="_ref_13680"><a href="structured-data.html#sec-issharedarraybuffer">IsSharedArrayBuffer</a></emu-xref>(<var>targetBuffer</var>) is <emu-val>true</emu-val>, and <var>srcBuffer</var>.<var class="field">[[ArrayBufferData]]</var> is <var>targetBuffer</var>.<var class="field">[[ArrayBufferData]]</var>, let <var>sameSharedArrayBuffer</var> be <emu-val>true</emu-val>; else let <var>sameSharedArrayBuffer</var> be <emu-val>false</emu-val>.</li><li>If <emu-xref aoid="SameValue" id="_ref_13681"><a href="abstract-operations.html#sec-samevalue">SameValue</a></emu-xref>(<var>srcBuffer</var>, <var>targetBuffer</var>) is <emu-val>true</emu-val> or <var>sameSharedArrayBuffer</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>srcByteLength</var> be <emu-xref aoid="TypedArrayByteLength" id="_ref_13682"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraybytelength">TypedArrayByteLength</a></emu-xref>(<var>srcRecord</var>).</li><li>Set <var>srcBuffer</var> to ?&nbsp;<emu-xref aoid="CloneArrayBuffer" id="_ref_13683"><a href="structured-data.html#sec-clonearraybuffer">CloneArrayBuffer</a></emu-xref>(<var>srcBuffer</var>, <var>srcByteOffset</var>, <var>srcByteLength</var>).</li><li>Let <var>srcByteIndex</var> be 0.</li></ol></li><li>Else,<ol><li>Let <var>srcByteIndex</var> be <var>srcByteOffset</var>.</li></ol></li><li>Let <var>targetByteIndex</var> be (<var>targetOffset</var> × <var>targetElementSize</var>) + <var>targetByteOffset</var>.</li><li>Let <var>limit</var> be <var>targetByteIndex</var> + (<var>targetElementSize</var> × <var>srcLength</var>).</li><li>If <var>srcType</var> is <var>targetType</var>, then<ol><li>NOTE: The transfer must be performed in a manner that preserves the bit-level encoding of the source data.</li><li>Repeat, while <var>targetByteIndex</var> &lt; <var>limit</var>,<ol><li>Let <var>value</var> be <emu-xref aoid="GetValueFromBuffer" id="_ref_13684"><a href="structured-data.html#sec-getvaluefrombuffer">GetValueFromBuffer</a></emu-xref>(<var>srcBuffer</var>, <var>srcByteIndex</var>, <emu-const>uint8</emu-const>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Perform <emu-xref aoid="SetValueInBuffer" id="_ref_13685"><a href="structured-data.html#sec-setvalueinbuffer">SetValueInBuffer</a></emu-xref>(<var>targetBuffer</var>, <var>targetByteIndex</var>, <emu-const>uint8</emu-const>, <var>value</var>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Set <var>srcByteIndex</var> to <var>srcByteIndex</var> + 1.</li><li>Set <var>targetByteIndex</var> to <var>targetByteIndex</var> + 1.</li></ol></li></ol></li><li>Else,<ol><li>Repeat, while <var>targetByteIndex</var> &lt; <var>limit</var>,<ol><li>Let <var>value</var> be <emu-xref aoid="GetValueFromBuffer" id="_ref_13686"><a href="structured-data.html#sec-getvaluefrombuffer">GetValueFromBuffer</a></emu-xref>(<var>srcBuffer</var>, <var>srcByteIndex</var>, <var>srcType</var>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Perform <emu-xref aoid="SetValueInBuffer" id="_ref_13687"><a href="structured-data.html#sec-setvalueinbuffer">SetValueInBuffer</a></emu-xref>(<var>targetBuffer</var>, <var>targetByteIndex</var>, <var>targetType</var>, <var>value</var>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Set <var>srcByteIndex</var> to <var>srcByteIndex</var> + <var>srcElementSize</var>.</li><li>Set <var>targetByteIndex</var> to <var>targetByteIndex</var> + <var>targetElementSize</var>.</li></ol></li></ol></li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.slice" type="built-in function">
<h1><span class="secnum">23.2.3.27</span> %TypedArray%.prototype.slice ( <var>start</var>, <var>end</var> )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.slice</code> as defined in <emu-xref href="#sec-array.prototype.slice" id="_ref_756"><a href="indexed-collections.html#sec-array.prototype.slice">23.1.3.28</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13688"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>srcArrayLength</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13689"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13690"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>startIndex</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>startIndex</var> be <emu-xref aoid="max" id="_ref_13691"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>srcArrayLength</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>startIndex</var> be <emu-xref aoid="min" id="_ref_13692"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>srcArrayLength</var>).</li><li>If <var>end</var> is <emu-val>undefined</emu-val>, let <var>relativeEnd</var> be <var>srcArrayLength</var>; else let <var>relativeEnd</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13693"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>end</var>).</li><li>If <var>relativeEnd</var> = -∞, let <var>endIndex</var> be 0.</li><li>Else if <var>relativeEnd</var> &lt; 0, let <var>endIndex</var> be <emu-xref aoid="max" id="_ref_13694"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>srcArrayLength</var> + <var>relativeEnd</var>, 0).</li><li>Else, let <var>endIndex</var> be <emu-xref aoid="min" id="_ref_13695"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeEnd</var>, <var>srcArrayLength</var>).</li><li>Let <var>countBytes</var> be <emu-xref aoid="max" id="_ref_13696"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>endIndex</var> - <var>startIndex</var>, 0).</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="TypedArraySpeciesCreate" id="_ref_13697"><a href="indexed-collections.html#typedarray-species-create" class="e-user-code">TypedArraySpeciesCreate</a></emu-xref>(<var>O</var>, « <emu-xref aoid="𝔽" id="_ref_13698"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>countBytes</var>)&nbsp;»).</li><li>If <var>countBytes</var> &gt; 0, then<ol><li>Set <var>taRecord</var> to <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13699"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13700"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Set <var>endIndex</var> to <emu-xref aoid="min" id="_ref_13701"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>endIndex</var>, <emu-xref aoid="TypedArrayLength" id="_ref_13702"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>)).</li><li>Set <var>countBytes</var> to <emu-xref aoid="max" id="_ref_13703"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>endIndex</var> - <var>startIndex</var>, 0).</li><li>Let <var>srcType</var> be <emu-xref aoid="TypedArrayElementType" id="_ref_13704"><a href="indexed-collections.html#sec-typedarrayelementtype">TypedArrayElementType</a></emu-xref>(<var>O</var>).</li><li>Let <var>targetType</var> be <emu-xref aoid="TypedArrayElementType" id="_ref_13705"><a href="indexed-collections.html#sec-typedarrayelementtype">TypedArrayElementType</a></emu-xref>(<var>A</var>).</li><li>If <var>srcType</var> is <var>targetType</var>, then<ol><li>NOTE: The transfer must be performed in a manner that preserves the bit-level encoding of the source data.</li><li>Let <var>srcBuffer</var> be <var>O</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Let <var>targetBuffer</var> be <var>A</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Let <var>elementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13706"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>O</var>).</li><li>Let <var>srcByteOffset</var> be <var>O</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Let <var>srcByteIndex</var> be (<var>startIndex</var> × <var>elementSize</var>) + <var>srcByteOffset</var>.</li><li>Let <var>targetByteIndex</var> be <var>A</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Let <var>endByteIndex</var> be <var>targetByteIndex</var> + (<var>countBytes</var> × <var>elementSize</var>).</li><li>Repeat, while <var>targetByteIndex</var> &lt; <var>endByteIndex</var>,<ol><li>Let <var>value</var> be <emu-xref aoid="GetValueFromBuffer" id="_ref_13707"><a href="structured-data.html#sec-getvaluefrombuffer">GetValueFromBuffer</a></emu-xref>(<var>srcBuffer</var>, <var>srcByteIndex</var>, <emu-const>uint8</emu-const>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Perform <emu-xref aoid="SetValueInBuffer" id="_ref_13708"><a href="structured-data.html#sec-setvalueinbuffer">SetValueInBuffer</a></emu-xref>(<var>targetBuffer</var>, <var>targetByteIndex</var>, <emu-const>uint8</emu-const>, <var>value</var>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Set <var>srcByteIndex</var> to <var>srcByteIndex</var> + 1.</li><li>Set <var>targetByteIndex</var> to <var>targetByteIndex</var> + 1.</li></ol></li></ol></li><li>Else,<ol><li>Let <var>n</var> be 0.</li><li>Let <var>k</var> be <var>startIndex</var>.</li><li>Repeat, while <var>k</var> &lt; <var>endIndex</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13709"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13710"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13711"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13712"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13713"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13714"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>n</var>)), <var>kValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li><li>Set <var>n</var> to <var>n</var> + 1.</li></ol></li></ol></li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.some" type="built-in function">
<h1><span class="secnum">23.2.3.28</span> %TypedArray%.prototype.some ( <var>callback</var> [ , <var>thisArg</var> ] )</h1>
<p>The interpretation and use of the arguments of this method are the same as for <code>Array.prototype.some</code> as defined in <emu-xref href="#sec-array.prototype.some" id="_ref_757"><a href="indexed-collections.html#sec-array.prototype.some">23.1.3.29</a></emu-xref>.</p>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13715"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13716"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_13717"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>callback</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13718"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13719"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13720"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>testResult</var> be <emu-xref aoid="ToBoolean" id="_ref_13721"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_13722"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>callback</var>, <var>thisArg</var>, « <var>kValue</var>, <emu-xref aoid="𝔽" id="_ref_13723"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>), <var>O</var>&nbsp;»)).</li><li>If <var>testResult</var> is <emu-val>true</emu-val>, return <emu-val>true</emu-val>.</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-val>false</emu-val>.</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.sort" oldids="sec-typedarraysortcompare" type="built-in function"><span id="sec-typedarraysortcompare"></span>
<h1><span class="secnum">23.2.3.29</span> %TypedArray%.prototype.sort ( <var>comparator</var> )</h1>
<p>This is a distinct method that, except as described below, implements the same requirements as those of <code>Array.prototype.sort</code> as defined in <emu-xref href="#sec-array.prototype.sort" id="_ref_758"><a href="indexed-collections.html#sec-array.prototype.sort">23.1.3.30</a></emu-xref>. The implementation of this method may be optimized with the knowledge that the <emu-val>this</emu-val> value is an object that has a fixed length and whose <emu-xref href="#integer-index" id="_ref_13724"><a href="ecmascript-data-types-and-values.html#integer-index">integer-indexed</a></emu-xref> properties are not sparse.</p>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>If <var>comparator</var> is not <emu-val>undefined</emu-val> and <emu-xref aoid="IsCallable" id="_ref_13725"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>comparator</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>obj</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13726"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>obj</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13727"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>NOTE: The following closure performs a numeric comparison rather than the string comparison used in <emu-xref href="#sec-array.prototype.sort" id="_ref_759"><a href="indexed-collections.html#sec-array.prototype.sort">23.1.3.30</a></emu-xref>.</li><li>Let <var>SortCompare</var> be a new <emu-xref href="#sec-abstract-closure" id="_ref_13728"><a href="ecmascript-data-types-and-values.html#sec-abstract-closure">Abstract Closure</a></emu-xref> with parameters (<var>x</var>, <var>y</var>) that captures <var>comparator</var> and performs the following steps when called:<ol><li>Return ?&nbsp;<emu-xref aoid="CompareTypedArrayElements" id="_ref_13729"><a href="indexed-collections.html#sec-comparetypedarrayelements">CompareTypedArrayElements</a></emu-xref>(<var>x</var>, <var>y</var>, <var>comparator</var>).</li></ol></li><li>Let <var>sortedList</var> be ?&nbsp;<emu-xref aoid="SortIndexedProperties" id="_ref_13730"><a href="indexed-collections.html#sec-sortindexedproperties" class="e-user-code">SortIndexedProperties</a></emu-xref>(<var>obj</var>, <var>len</var>, <var>SortCompare</var>, <emu-const>read-through-holes</emu-const>).</li><li>Let <var>j</var> be 0.</li><li>Repeat, while <var>j</var> &lt; <var>len</var>,<ol><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13731"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>obj</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13732"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13733"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>j</var>)), <var>sortedList</var>[<var>j</var>], <emu-val>true</emu-val>).</li><li>Set <var>j</var> to <var>j</var> + 1.</li></ol></li><li>Return <var>obj</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>Because <emu-val>NaN</emu-val> always compares greater than any other value (see <emu-xref aoid="CompareTypedArrayElements" id="_ref_13734"><a href="indexed-collections.html#sec-comparetypedarrayelements">CompareTypedArrayElements</a></emu-xref>), <emu-val>NaN</emu-val> property values always sort to the end of the result when <var>comparator</var> is not provided.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.subarray" type="built-in function">
<h1><span class="secnum">23.2.3.30</span> %TypedArray%.prototype.subarray ( <var>start</var>, <var>end</var> )</h1>
<p>This method returns a new <var>TypedArray</var> whose element type is the element type of this <var>TypedArray</var> and whose ArrayBuffer is the ArrayBuffer of this <var>TypedArray</var>, referencing the elements in the <emu-xref href="#interval" id="_ref_13735"><a href="notational-conventions.html#interval">interval</a></emu-xref> from <var>start</var> (inclusive) to <var>end</var> (exclusive). If either <var>start</var> or <var>end</var> is negative, it refers to an index from the end of the array, as opposed to from the beginning.</p>
<p>It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="RequireInternalSlot" id="_ref_13736"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[TypedArrayName]]</var>).</li><li><emu-xref href="#assert" id="_ref_13737"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>O</var> has a <var class="field">[[ViewedArrayBuffer]]</var> internal slot.</li><li>Let <var>buffer</var> be <var>O</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Let <var>srcRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13738"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13739"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>srcRecord</var>) is <emu-val>true</emu-val>, then<ol><li>Let <var>srcLength</var> be 0.</li></ol></li><li>Else,<ol><li>Let <var>srcLength</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13740"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>srcRecord</var>).</li></ol></li><li>Let <var>relativeStart</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13741"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>start</var>).</li><li>If <var>relativeStart</var> = -∞, let <var>startIndex</var> be 0.</li><li>Else if <var>relativeStart</var> &lt; 0, let <var>startIndex</var> be <emu-xref aoid="max" id="_ref_13742"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>srcLength</var> + <var>relativeStart</var>, 0).</li><li>Else, let <var>startIndex</var> be <emu-xref aoid="min" id="_ref_13743"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeStart</var>, <var>srcLength</var>).</li><li>Let <var>elementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13744"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>O</var>).</li><li>Let <var>srcByteOffset</var> be <var>O</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Let <var>beginByteOffset</var> be <var>srcByteOffset</var> + (<var>startIndex</var> × <var>elementSize</var>).</li><li>If <var>O</var>.<var class="field">[[ArrayLength]]</var> is <emu-const>auto</emu-const> and <var>end</var> is <emu-val>undefined</emu-val>, then<ol><li>Let <var>argumentsList</var> be « <var>buffer</var>, <emu-xref aoid="𝔽" id="_ref_13745"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>beginByteOffset</var>)&nbsp;».</li></ol></li><li>Else,<ol><li>If <var>end</var> is <emu-val>undefined</emu-val>, let <var>relativeEnd</var> be <var>srcLength</var>; else let <var>relativeEnd</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13746"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>end</var>).</li><li>If <var>relativeEnd</var> = -∞, let <var>endIndex</var> be 0.</li><li>Else if <var>relativeEnd</var> &lt; 0, let <var>endIndex</var> be <emu-xref aoid="max" id="_ref_13747"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>srcLength</var> + <var>relativeEnd</var>, 0).</li><li>Else, let <var>endIndex</var> be <emu-xref aoid="min" id="_ref_13748"><a href="notational-conventions.html#eqn-min">min</a></emu-xref>(<var>relativeEnd</var>, <var>srcLength</var>).</li><li>Let <var>newLength</var> be <emu-xref aoid="max" id="_ref_13749"><a href="notational-conventions.html#eqn-max">max</a></emu-xref>(<var>endIndex</var> - <var>startIndex</var>, 0).</li><li>Let <var>argumentsList</var> be « <var>buffer</var>, <emu-xref aoid="𝔽" id="_ref_13750"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>beginByteOffset</var>), <emu-xref aoid="𝔽" id="_ref_13751"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>newLength</var>)&nbsp;».</li></ol></li><li>Return ?&nbsp;<emu-xref aoid="TypedArraySpeciesCreate" id="_ref_13752"><a href="indexed-collections.html#typedarray-species-create" class="e-user-code">TypedArraySpeciesCreate</a></emu-xref>(<var>O</var>, <var>argumentsList</var>).</li></ol></emu-alg>
<p>This method is not generic. The <emu-val>this</emu-val> value must be an object with a <var class="field">[[TypedArrayName]]</var> internal slot.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.tolocalestring" type="built-in function">
<h1><span class="secnum">23.2.3.31</span> %TypedArray%.prototype.toLocaleString ( [ <var>reserved1</var> [ , <var>reserved2</var> ] ] )</h1>
<p>This is a distinct method that implements the same algorithm as <code>Array.prototype.toLocaleString</code> as defined in <emu-xref href="#sec-array.prototype.tolocalestring" id="_ref_760"><a href="indexed-collections.html#sec-array.prototype.tolocalestring">23.1.3.32</a></emu-xref> except that <emu-xref aoid="TypedArrayLength" id="_ref_13753"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref> is called in place of performing a <var class="field">[[Get]]</var> of <emu-val>"length"</emu-val>. The implementation of the algorithm may be optimized with the knowledge that the <emu-val>this</emu-val> value has a fixed length when the underlying buffer is not resizable and whose <emu-xref href="#integer-index" id="_ref_13754"><a href="ecmascript-data-types-and-values.html#integer-index">integer-indexed</a></emu-xref> properties are not sparse. However, such optimization must not introduce any observable changes in the specified behaviour of the algorithm.</p>
<p>This method is not generic. <emu-xref aoid="ValidateTypedArray" id="_ref_13755"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref> is called with the <emu-val>this</emu-val> value and <emu-const>seq-cst</emu-const> as arguments prior to evaluating the algorithm. If its result is an <emu-xref href="#sec-completion-record-specification-type" id="_ref_13756"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">abrupt completion</a></emu-xref> that exception is thrown instead of evaluating the algorithm.</p>
<emu-note><span class="note">Note</span><div class="note-contents">
<p>If the ECMAScript implementation includes the ECMA-402 Internationalization API this method is based upon the algorithm for <code>Array.prototype.toLocaleString</code> that is in the ECMA-402 specification.</p>
</div></emu-note>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.toreversed" type="built-in function">
<h1><span class="secnum">23.2.3.32</span> %TypedArray%.prototype.toReversed ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13757"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13758"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="TypedArrayCreateSameType" id="_ref_13759"><a href="indexed-collections.html#sec-typedarray-create-same-type">TypedArrayCreateSameType</a></emu-xref>(<var>O</var>, <var>len</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>from</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13760"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13761"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>len</var> - <var>k</var> - 1)).</li><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13762"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13763"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>fromValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13764"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>from</var>).</li><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13765"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>fromValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.tosorted" type="built-in function">
<h1><span class="secnum">23.2.3.33</span> %TypedArray%.prototype.toSorted ( <var>comparator</var> )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>If <var>comparator</var> is not <emu-val>undefined</emu-val> and <emu-xref aoid="IsCallable" id="_ref_13766"><a href="abstract-operations.html#sec-iscallable">IsCallable</a></emu-xref>(<var>comparator</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13767"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13768"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="TypedArrayCreateSameType" id="_ref_13769"><a href="indexed-collections.html#sec-typedarray-create-same-type">TypedArrayCreateSameType</a></emu-xref>(<var>O</var>, <var>len</var>).</li><li>NOTE: The following closure performs a numeric comparison rather than the string comparison used in <emu-xref href="#sec-array.prototype.tosorted" id="_ref_761"><a href="indexed-collections.html#sec-array.prototype.tosorted">23.1.3.34</a></emu-xref>.</li><li>Let <var>SortCompare</var> be a new <emu-xref href="#sec-abstract-closure" id="_ref_13770"><a href="ecmascript-data-types-and-values.html#sec-abstract-closure">Abstract Closure</a></emu-xref> with parameters (<var>x</var>, <var>y</var>) that captures <var>comparator</var> and performs the following steps when called:<ol><li>Return ?&nbsp;<emu-xref aoid="CompareTypedArrayElements" id="_ref_13771"><a href="indexed-collections.html#sec-comparetypedarrayelements">CompareTypedArrayElements</a></emu-xref>(<var>x</var>, <var>y</var>, <var>comparator</var>).</li></ol></li><li>Let <var>sortedList</var> be ?&nbsp;<emu-xref aoid="SortIndexedProperties" id="_ref_13772"><a href="indexed-collections.html#sec-sortindexedproperties" class="e-user-code">SortIndexedProperties</a></emu-xref>(<var>O</var>, <var>len</var>, <var>SortCompare</var>, <emu-const>read-through-holes</emu-const>).</li><li>Let <var>j</var> be 0.</li><li>Repeat, while <var>j</var> &lt; <var>len</var>,<ol><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13773"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>A</var>, !&nbsp;<emu-xref aoid="ToString" id="_ref_13774"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13775"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>j</var>)), <var>sortedList</var>[<var>j</var>], <emu-val>true</emu-val>).</li><li>Set <var>j</var> to <var>j</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.tostring" type="built-in function">
<h1><span class="secnum">23.2.3.34</span> %TypedArray%.prototype.toString ( )</h1>
<p>The initial value of the <emu-val>"toString"</emu-val> property is %Array.prototype.toString%, defined in <emu-xref href="#sec-array.prototype.tostring" id="_ref_762"><a href="indexed-collections.html#sec-array.prototype.tostring">23.1.3.36</a></emu-xref>.</p>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.values" type="built-in function">
<h1><span class="secnum">23.2.3.35</span> %TypedArray%.prototype.values ( )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13776"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Return <emu-xref aoid="CreateArrayIterator" id="_ref_13777"><a href="indexed-collections.html#sec-createarrayiterator">CreateArrayIterator</a></emu-xref>(<var>O</var>, <emu-const>value</emu-const>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-%typedarray%.prototype.with" type="built-in function">
<h1><span class="secnum">23.2.3.36</span> %TypedArray%.prototype.with ( <var>index</var>, <var>value</var> )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13778"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>O</var>, <emu-const>seq-cst</emu-const>).</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13779"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>relativeIndex</var> be ?&nbsp;<emu-xref aoid="ToIntegerOrInfinity" id="_ref_13780"><a href="abstract-operations.html#sec-tointegerorinfinity" class="e-user-code">ToIntegerOrInfinity</a></emu-xref>(<var>index</var>).</li><li>If <var>relativeIndex</var> ≥ 0, let <var>actualIndex</var> be <var>relativeIndex</var>.</li><li>Else, let <var>actualIndex</var> be <var>len</var> + <var>relativeIndex</var>.</li><li>If <var>O</var>.<var class="field">[[ContentType]]</var> is <emu-const>bigint</emu-const>, let <var>numericValue</var> be ?&nbsp;<emu-xref aoid="ToBigInt" id="_ref_13781"><a href="abstract-operations.html#sec-tobigint" class="e-user-code">ToBigInt</a></emu-xref>(<var>value</var>).</li><li>Else, let <var>numericValue</var> be ?&nbsp;<emu-xref aoid="ToNumber" id="_ref_13782"><a href="abstract-operations.html#sec-tonumber" class="e-user-code">ToNumber</a></emu-xref>(<var>value</var>).</li><li>If <emu-xref aoid="IsValidIntegerIndex" id="_ref_13783"><a href="ordinary-and-exotic-objects-behaviours.html#sec-isvalidintegerindex">IsValidIntegerIndex</a></emu-xref>(<var>O</var>, <emu-xref aoid="𝔽" id="_ref_13784"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>actualIndex</var>)) is <emu-val>false</emu-val>, throw a <emu-val>RangeError</emu-val> exception.</li><li>Let <var>A</var> be ?&nbsp;<emu-xref aoid="TypedArrayCreateSameType" id="_ref_13785"><a href="indexed-collections.html#sec-typedarray-create-same-type">TypedArrayCreateSameType</a></emu-xref>(<var>O</var>, <var>len</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13786"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13787"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>If <var>k</var> = <var>actualIndex</var>, let <var>fromValue</var> be <var>numericValue</var>.</li><li>Else, let <var>fromValue</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_13788"><a href="abstract-operations.html#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Perform !&nbsp;<emu-xref aoid="Set" id="_ref_13789"><a href="abstract-operations.html#sec-set-o-p-v-throw">Set</a></emu-xref>(<var>A</var>, <var>Pk</var>, <var>fromValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>A</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause oldids="sec-%typedarray%.prototype-@@iterator" id="sec-%typedarray%.prototype-%symbol.iterator%" type="built-in function"><span id="sec-%typedarray%.prototype-@@iterator"></span>
<h1><span class="secnum">23.2.3.37</span> %TypedArray%.prototype [ %Symbol.iterator% ] ( )</h1>
<p>The initial value of the <emu-xref href="#sec-well-known-symbols" id="_ref_13790"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref> property is %TypedArray.prototype.values%, defined in <emu-xref href="#sec-%typedarray%.prototype.values" id="_ref_763"><a href="indexed-collections.html#sec-%typedarray%.prototype.values">23.2.3.35</a></emu-xref>.</p>
</emu-clause>
<emu-clause oldids="sec-get-%typedarray%.prototype-@@tostringtag" id="sec-get-%typedarray%.prototype-%symbol.tostringtag%" type="built-in function"><span id="sec-get-%typedarray%.prototype-@@tostringtag"></span>
<h1><span class="secnum">23.2.3.38</span> get %TypedArray%.prototype [ %Symbol.toStringTag% ]</h1>
<p><emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13791"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>.prototype[%Symbol.toStringTag%]</code> is an <emu-xref href="#sec-object-type" id="_ref_13792"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> whose set accessor function is <emu-val>undefined</emu-val>. Its get accessor function performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>If <var>O</var> <emu-xref href="#sec-object-type" id="_ref_13793"><a href="ecmascript-data-types-and-values.html#sec-object-type">is not an Object</a></emu-xref>, return <emu-val>undefined</emu-val>.</li><li>If <var>O</var> does not have a <var class="field">[[TypedArrayName]]</var> internal slot, return <emu-val>undefined</emu-val>.</li><li>Let <var>name</var> be <var>O</var>.<var class="field">[[TypedArrayName]]</var>.</li><li><emu-xref href="#assert" id="_ref_13794"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>name</var> <emu-xref href="#sec-ecmascript-language-types-string-type" id="_ref_13795"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-string-type">is a String</a></emu-xref>.</li><li>Return <var>name</var>.</li></ol></emu-alg>
<p>This property has the attributes { <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>true</emu-val> }.</p>
<p>The initial value of the <emu-val>"name"</emu-val> property of this function is <emu-val>"get [Symbol.toStringTag]"</emu-val>.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-abstract-operations-for-typedarray-objects">
<h1><span class="secnum">23.2.4</span> Abstract Operations for TypedArray Objects</h1>
<emu-clause id="sec-typedarraycreatefromconstructor" oldids="typedarray-create" type="abstract operation" aoid="TypedArrayCreateFromConstructor"><span id="typedarray-create"></span>
<h1><span class="secnum">23.2.4.1</span> TypedArrayCreateFromConstructor ( <var>constructor</var>, <var>argumentList</var> )</h1>
<p>The abstract operation TypedArrayCreateFromConstructor takes arguments <var>constructor</var> (a <emu-xref href="#constructor" id="_ref_13796"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>) and <var>argumentList</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_13797"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-ecmascript-language-types" id="_ref_13798"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13799"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#typedarray" id="_ref_13800"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13801"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It is used to specify the creation of a new <emu-xref href="#typedarray" id="_ref_13802"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> using a <emu-xref href="#constructor" id="_ref_13803"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> function. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>newTypedArray</var> be ?&nbsp;<emu-xref aoid="Construct" id="_ref_13804"><a href="abstract-operations.html#sec-construct" class="e-user-code">Construct</a></emu-xref>(<var>constructor</var>, <var>argumentList</var>).</li><li>Let <var>taRecord</var> be ?&nbsp;<emu-xref aoid="ValidateTypedArray" id="_ref_13805"><a href="indexed-collections.html#sec-validatetypedarray">ValidateTypedArray</a></emu-xref>(<var>newTypedArray</var>, <emu-const>seq-cst</emu-const>).</li><li><emu-xref href="#assert" id="_ref_13806"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>newTypedArray</var> has all the internal slots mentioned in <emu-xref href="#sec-properties-of-typedarray-instances" title="" id="_ref_764"><a href="indexed-collections.html#sec-properties-of-typedarray-instances">Properties of <var>TypedArray</var> Instances</a></emu-xref>.</li><li>If the number of elements in <var>argumentList</var> is 1 and <var>argumentList</var>[0] <emu-xref href="#sec-ecmascript-language-types-number-type" id="_ref_13807"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-number-type">is a Number</a></emu-xref>, then<ol><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13808"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>length</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13809"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>If <var>length</var> &lt; <emu-xref aoid="" id="_ref_13810"><a href="notational-conventions.html#%E2%84%9D"></a></emu-xref>(<var>argumentList</var>[0]), throw a <emu-val>TypeError</emu-val> exception.</li></ol></li><li>Return <var>newTypedArray</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-typedarray-create-same-type" type="abstract operation" aoid="TypedArrayCreateSameType">
<h1><span class="secnum">23.2.4.2</span> TypedArrayCreateSameType ( <var>exemplar</var>, <var>length</var> )</h1>
<p>The abstract operation TypedArrayCreateSameType takes arguments <var>exemplar</var> (a <emu-xref href="#typedarray" id="_ref_13811"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and <var>length</var> (a non-negative <emu-xref href="#integer" id="_ref_13812"><a href="notational-conventions.html#integer">integer</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13813"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#typedarray" id="_ref_13814"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13815"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It is used to specify the creation of a new <emu-xref href="#typedarray" id="_ref_13816"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> using a <emu-xref href="#constructor" id="_ref_13817"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> function that is derived from <var>exemplar</var>. Unlike <emu-xref aoid="TypedArraySpeciesCreate" id="_ref_13818"><a href="indexed-collections.html#typedarray-species-create">TypedArraySpeciesCreate</a></emu-xref>, which can construct custom <emu-xref href="#typedarray" id="_ref_13819"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> subclasses through the use of <emu-xref href="#sec-well-known-symbols" id="_ref_13820"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.species%</a></emu-xref>, this operation always uses one of the built-in <emu-xref href="#typedarray" id="_ref_13821"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> <emu-xref href="#constructor" id="_ref_13822"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>constructor</var> be the intrinsic object associated with the <emu-xref href="#constructor" id="_ref_13823"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> name <var>exemplar</var>.<var class="field">[[TypedArrayName]]</var> in <emu-xref href="#table-the-typedarray-constructors" id="_ref_765"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref>.</li><li>Let <var>result</var> be ?&nbsp;<emu-xref aoid="TypedArrayCreateFromConstructor" id="_ref_13824"><a href="indexed-collections.html#sec-typedarraycreatefromconstructor">TypedArrayCreateFromConstructor</a></emu-xref>(<var>constructor</var>, « <emu-xref aoid="𝔽" id="_ref_13825"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>length</var>)&nbsp;»).</li><li><emu-xref href="#assert" id="_ref_13826"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>result</var> has <var class="field">[[TypedArrayName]]</var> and <var class="field">[[ContentType]]</var> internal slots.</li><li><emu-xref href="#assert" id="_ref_13827"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>result</var>.<var class="field">[[ContentType]]</var> is <var>exemplar</var>.<var class="field">[[ContentType]]</var>.</li><li>Return <var>result</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="typedarray-species-create" type="abstract operation" aoid="TypedArraySpeciesCreate">
<h1><span class="secnum">23.2.4.3</span> TypedArraySpeciesCreate ( <var>exemplar</var>, <var>argumentList</var> )</h1>
<p>The abstract operation TypedArraySpeciesCreate takes arguments <var>exemplar</var> (a <emu-xref href="#typedarray" id="_ref_13828"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and <var>argumentList</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_13829"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-ecmascript-language-types" id="_ref_13830"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13831"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#typedarray" id="_ref_13832"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13833"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It is used to specify the creation of a new <emu-xref href="#typedarray" id="_ref_13834"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> using a <emu-xref href="#constructor" id="_ref_13835"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> function that is derived from <var>exemplar</var>. Unlike <emu-xref aoid="ArraySpeciesCreate" id="_ref_13836"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arrayspeciescreate">ArraySpeciesCreate</a></emu-xref>, which can create non-Array objects through the use of <emu-xref href="#sec-well-known-symbols" id="_ref_13837"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.species%</a></emu-xref>, this operation enforces that the <emu-xref href="#constructor" id="_ref_13838"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> function creates an actual <emu-xref href="#typedarray" id="_ref_13839"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>defaultConstructor</var> be the intrinsic object associated with the <emu-xref href="#constructor" id="_ref_13840"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> name <var>exemplar</var>.<var class="field">[[TypedArrayName]]</var> in <emu-xref href="#table-the-typedarray-constructors" id="_ref_766"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref>.</li><li>Let <var>constructor</var> be ?&nbsp;<emu-xref aoid="SpeciesConstructor" id="_ref_13841"><a href="abstract-operations.html#sec-speciesconstructor" class="e-user-code">SpeciesConstructor</a></emu-xref>(<var>exemplar</var>, <var>defaultConstructor</var>).</li><li>Let <var>result</var> be ?&nbsp;<emu-xref aoid="TypedArrayCreateFromConstructor" id="_ref_13842"><a href="indexed-collections.html#sec-typedarraycreatefromconstructor" class="e-user-code">TypedArrayCreateFromConstructor</a></emu-xref>(<var>constructor</var>, <var>argumentList</var>).</li><li>If <var>result</var>.<var class="field">[[ContentType]]</var> is not <var>exemplar</var>.<var class="field">[[ContentType]]</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Return <var>result</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-validatetypedarray" type="abstract operation" aoid="ValidateTypedArray">
<h1><span class="secnum">23.2.4.4</span> ValidateTypedArray ( <var>O</var>, <var>order</var> )</h1>
<p>The abstract operation ValidateTypedArray takes arguments <var>O</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_13843"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and <var>order</var> (<emu-const>seq-cst</emu-const> or <emu-const>unordered</emu-const>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13844"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#sec-typedarray-with-buffer-witness-records" id="_ref_13845"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarray-with-buffer-witness-records">TypedArray With Buffer Witness Record</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13846"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Perform ?&nbsp;<emu-xref aoid="RequireInternalSlot" id="_ref_13847"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>O</var>, <var class="field">[[TypedArrayName]]</var>).</li><li><emu-xref href="#assert" id="_ref_13848"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>O</var> has a <var class="field">[[ViewedArrayBuffer]]</var> internal slot.</li><li>Let <var>taRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13849"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>O</var>, <var>order</var>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13850"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Return <var>taRecord</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-typedarrayelementsize" type="abstract operation" aoid="TypedArrayElementSize">
<h1><span class="secnum">23.2.4.5</span> TypedArrayElementSize ( <var>O</var> )</h1>
<p>The abstract operation TypedArrayElementSize takes argument <var>O</var> (a <emu-xref href="#typedarray" id="_ref_13851"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and returns a non-negative <emu-xref href="#integer" id="_ref_13852"><a href="notational-conventions.html#integer">integer</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Return the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors" id="_ref_767"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref> for <var>O</var>.<var class="field">[[TypedArrayName]]</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-typedarrayelementtype" type="abstract operation" aoid="TypedArrayElementType">
<h1><span class="secnum">23.2.4.6</span> TypedArrayElementType ( <var>O</var> )</h1>
<p>The abstract operation TypedArrayElementType takes argument <var>O</var> (a <emu-xref href="#typedarray" id="_ref_13853"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and returns a <emu-xref href="#sec-typedarray-objects" id="_ref_13854"><a href="indexed-collections.html#sec-typedarray-objects">TypedArray element type</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Return the Element Type value specified in <emu-xref href="#table-the-typedarray-constructors" id="_ref_768"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref> for <var>O</var>.<var class="field">[[TypedArrayName]]</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-comparetypedarrayelements" type="abstract operation" aoid="CompareTypedArrayElements">
<h1><span class="secnum">23.2.4.7</span> CompareTypedArrayElements ( <var>x</var>, <var>y</var>, <var>comparator</var> )</h1>
<p>The abstract operation CompareTypedArrayElements takes arguments <var>x</var> (a Number or a BigInt), <var>y</var> (a Number or a BigInt), and <var>comparator</var> (a <emu-xref href="#function-object" id="_ref_13855"><a href="ecmascript-data-types-and-values.html#function-object">function object</a></emu-xref> or <emu-val>undefined</emu-val>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13856"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a Number or an <emu-xref href="#sec-completion-record-specification-type" id="_ref_13857"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">abrupt completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li><emu-xref href="#assert" id="_ref_13858"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>x</var> <emu-xref href="#sec-ecmascript-language-types-number-type" id="_ref_13859"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-number-type">is a Number</a></emu-xref> and <var>y</var> <emu-xref href="#sec-ecmascript-language-types-number-type" id="_ref_13860"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-number-type">is a Number</a></emu-xref>, or <var>x</var> <emu-xref href="#sec-ecmascript-language-types-bigint-type" id="_ref_13861"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-bigint-type">is a BigInt</a></emu-xref> and <var>y</var> <emu-xref href="#sec-ecmascript-language-types-bigint-type" id="_ref_13862"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-bigint-type">is a BigInt</a></emu-xref>.</li><li>If <var>comparator</var> is not <emu-val>undefined</emu-val>, then<ol><li>Let <var>v</var> be ?&nbsp;<emu-xref aoid="ToNumber" id="_ref_13863"><a href="abstract-operations.html#sec-tonumber" class="e-user-code">ToNumber</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_13864"><a href="abstract-operations.html#sec-call" class="e-user-code">Call</a></emu-xref>(<var>comparator</var>, <emu-val>undefined</emu-val>, « <var>x</var>, <var>y</var>&nbsp;»)).</li><li>If <var>v</var> is <emu-val>NaN</emu-val>, return <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>Return <var>v</var>.</li></ol></li><li>If <var>x</var> and <var>y</var> are both <emu-val>NaN</emu-val>, return <emu-val>+0</emu-val><sub>𝔽</sub>.</li><li>If <var>x</var> is <emu-val>NaN</emu-val>, return <emu-val>1</emu-val><sub>𝔽</sub>.</li><li>If <var>y</var> is <emu-val>NaN</emu-val>, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>x</var> &lt; <var>y</var>, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>x</var> &gt; <var>y</var>, return <emu-val>1</emu-val><sub>𝔽</sub>.</li><li>If <var>x</var> is <emu-val>-0</emu-val><sub>𝔽</sub> and <var>y</var> is <emu-val>+0</emu-val><sub>𝔽</sub>, return <emu-val>-1</emu-val><sub>𝔽</sub>.</li><li>If <var>x</var> is <emu-val>+0</emu-val><sub>𝔽</sub> and <var>y</var> is <emu-val>-0</emu-val><sub>𝔽</sub>, return <emu-val>1</emu-val><sub>𝔽</sub>.</li><li>Return <emu-val>+0</emu-val><sub>𝔽</sub>.</li></ol></emu-alg>
<emu-note><span class="note">Note</span><div class="note-contents">
This performs a numeric comparison rather than the string comparison used in <emu-xref href="#sec-comparearrayelements" id="_ref_769"><a href="indexed-collections.html#sec-comparearrayelements">23.1.3.30.2</a></emu-xref>.
</div></emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-typedarray-constructors">
<h1><span class="secnum">23.2.5</span> The <var>TypedArray</var> Constructors</h1>
<p>Each <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13865"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
<ul>
<li>is an intrinsic object that has the structure described below, differing only in the name used as the <emu-xref href="#constructor" id="_ref_13866"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> name instead of <var>TypedArray</var>, in <emu-xref href="#table-the-typedarray-constructors" id="_ref_770"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref>, except where otherwise noted.</li>
<li>is a function whose behaviour differs based upon the number and types of its arguments. The actual behaviour of a call of <var>TypedArray</var> depends upon the number and kind of arguments that are passed to it.</li>
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
<li>may be used as the value of an <code>extends</code> clause of a class definition. Subclass <emu-xref href="#constructor" id="_ref_13867"><a href="ecmascript-data-types-and-values.html#constructor">constructors</a></emu-xref> that intend to inherit the specified <var>TypedArray</var> behaviour must include a <code>super</code> call to the <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13868"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> to create and initialize the subclass instance with the internal state necessary to support the <emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13869"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref><code>.prototype</code> built-in methods.</li>
</ul>
<emu-clause id="sec-typedarray" oldids="sec-typedarray-length,sec-typedarray-object" type="built-in function"><span id="sec-typedarray-object"></span><span id="sec-typedarray-length"></span>
<h1><span class="secnum">23.2.5.1</span> <var>TypedArray</var> ( ...<var>args</var> )</h1>
<p>Each <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13870"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> performs the following steps when called:</p>
<emu-alg><ol><li>If NewTarget is <emu-val>undefined</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>constructorName</var> be the String value of the <emu-xref href="#constructor" id="_ref_13871"><a href="ecmascript-data-types-and-values.html#constructor">Constructor</a></emu-xref> Name value specified in <emu-xref href="#table-the-typedarray-constructors" id="_ref_771"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref> for this <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13872"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>.</li><li>Let <var>proto</var> be <code>"%<var>TypedArray</var>.prototype%"</code>.</li><li>Let <var>numberOfArgs</var> be the number of elements in <var>args</var>.</li><li>If <var>numberOfArgs</var> = 0, return ?&nbsp;<emu-xref aoid="AllocateTypedArray" id="_ref_13873"><a href="indexed-collections.html#sec-allocatetypedarray" class="e-user-code">AllocateTypedArray</a></emu-xref>(<var>constructorName</var>, NewTarget, <var>proto</var>, 0).</li><li>Let <var>firstArgument</var> be <var>args</var>[0].</li><li>If <var>firstArgument</var> <emu-xref href="#sec-object-type" id="_ref_13874"><a href="ecmascript-data-types-and-values.html#sec-object-type">is an Object</a></emu-xref>, then<ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="AllocateTypedArray" id="_ref_13875"><a href="indexed-collections.html#sec-allocatetypedarray" class="e-user-code">AllocateTypedArray</a></emu-xref>(<var>constructorName</var>, NewTarget, <var>proto</var>).</li><li>If <var>firstArgument</var> has a <var class="field">[[TypedArrayName]]</var> internal slot, then<ol><li>Perform ?&nbsp;<emu-xref aoid="InitializeTypedArrayFromTypedArray" id="_ref_13876"><a href="indexed-collections.html#sec-initializetypedarrayfromtypedarray">InitializeTypedArrayFromTypedArray</a></emu-xref>(<var>O</var>, <var>firstArgument</var>).</li></ol></li><li>Else if <var>firstArgument</var> has an <var class="field">[[ArrayBufferData]]</var> internal slot, then<ol><li>If <var>numberOfArgs</var> &gt; 1, let <var>byteOffset</var> be <var>args</var>[1]; else let <var>byteOffset</var> be <emu-val>undefined</emu-val>.</li><li>If <var>numberOfArgs</var> &gt; 2, let <var>length</var> be <var>args</var>[2]; else let <var>length</var> be <emu-val>undefined</emu-val>.</li><li>Perform ?&nbsp;<emu-xref aoid="InitializeTypedArrayFromArrayBuffer" id="_ref_13877"><a href="indexed-collections.html#sec-initializetypedarrayfromarraybuffer" class="e-user-code">InitializeTypedArrayFromArrayBuffer</a></emu-xref>(<var>O</var>, <var>firstArgument</var>, <var>byteOffset</var>, <var>length</var>).</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_13878"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>firstArgument</var> <emu-xref href="#sec-object-type" id="_ref_13879"><a href="ecmascript-data-types-and-values.html#sec-object-type">is an Object</a></emu-xref> and <var>firstArgument</var> does not have either a <var class="field">[[TypedArrayName]]</var> or an <var class="field">[[ArrayBufferData]]</var> internal slot.</li><li>Let <var>usingIterator</var> be ?&nbsp;<emu-xref aoid="GetMethod" id="_ref_13880"><a href="abstract-operations.html#sec-getmethod" class="e-user-code">GetMethod</a></emu-xref>(<var>firstArgument</var>, <emu-xref href="#sec-well-known-symbols" id="_ref_13881"><a href="ecmascript-data-types-and-values.html#sec-well-known-symbols">%Symbol.iterator%</a></emu-xref>).</li><li>If <var>usingIterator</var> is not <emu-val>undefined</emu-val>, then<ol><li>Let <var>values</var> be ?&nbsp;<emu-xref aoid="IteratorToList" id="_ref_13882"><a href="abstract-operations.html#sec-iteratortolist" class="e-user-code">IteratorToList</a></emu-xref>(? <emu-xref aoid="GetIteratorFromMethod" id="_ref_13883"><a href="abstract-operations.html#sec-getiteratorfrommethod" class="e-user-code">GetIteratorFromMethod</a></emu-xref>(<var>firstArgument</var>, <var>usingIterator</var>)).</li><li>Perform ?&nbsp;<emu-xref aoid="InitializeTypedArrayFromList" id="_ref_13884"><a href="indexed-collections.html#sec-initializetypedarrayfromlist" class="e-user-code">InitializeTypedArrayFromList</a></emu-xref>(<var>O</var>, <var>values</var>).</li></ol></li><li>Else,<ol><li>NOTE: <var>firstArgument</var> is not an <emu-xref href="#sec-iterable-interface" id="_ref_13885"><a href="control-abstraction-objects.html#sec-iterable-interface">iterable object</a></emu-xref>, so assume it is already an <emu-xref href="#sec-lengthofarraylike" id="_ref_13886"><a href="abstract-operations.html#sec-lengthofarraylike">array-like object</a></emu-xref>.</li><li>Perform ?&nbsp;<emu-xref aoid="InitializeTypedArrayFromArrayLike" id="_ref_13887"><a href="indexed-collections.html#sec-initializetypedarrayfromarraylike" class="e-user-code">InitializeTypedArrayFromArrayLike</a></emu-xref>(<var>O</var>, <var>firstArgument</var>).</li></ol></li></ol></li><li>Return <var>O</var>.</li></ol></li><li><emu-xref href="#assert" id="_ref_13888"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>firstArgument</var> <emu-xref href="#sec-object-type" id="_ref_13889"><a href="ecmascript-data-types-and-values.html#sec-object-type">is not an Object</a></emu-xref>.</li><li>Let <var>elementLength</var> be ?&nbsp;<emu-xref aoid="ToIndex" id="_ref_13890"><a href="abstract-operations.html#sec-toindex" class="e-user-code">ToIndex</a></emu-xref>(<var>firstArgument</var>).</li><li>Return ?&nbsp;<emu-xref aoid="AllocateTypedArray" id="_ref_13891"><a href="indexed-collections.html#sec-allocatetypedarray" class="e-user-code">AllocateTypedArray</a></emu-xref>(<var>constructorName</var>, NewTarget, <var>proto</var>, <var>elementLength</var>).</li></ol></emu-alg>
<emu-clause id="sec-allocatetypedarray" type="abstract operation" aoid="AllocateTypedArray">
<h1><span class="secnum">23.2.5.1.1</span> AllocateTypedArray ( <var>constructorName</var>, <var>newTarget</var>, <var>defaultProto</var> [ , <var>length</var> ] )</h1>
<p>The abstract operation AllocateTypedArray takes arguments <var>constructorName</var> (a String which is the name of a <emu-xref href="#typedarray" id="_ref_13892"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> <emu-xref href="#constructor" id="_ref_13893"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> in <emu-xref href="#table-the-typedarray-constructors" id="_ref_772"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref>), <var>newTarget</var> (a <emu-xref href="#constructor" id="_ref_13894"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>), and <var>defaultProto</var> (a String) and optional argument <var>length</var> (a non-negative <emu-xref href="#integer" id="_ref_13895"><a href="notational-conventions.html#integer">integer</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13896"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#typedarray" id="_ref_13897"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13898"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It is used to validate and create an instance of a <emu-xref href="#typedarray" id="_ref_13899"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> <emu-xref href="#constructor" id="_ref_13900"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>. If the <var>length</var> argument is passed, an ArrayBuffer of that length is also allocated and associated with the new <emu-xref href="#typedarray" id="_ref_13901"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> instance. AllocateTypedArray provides common semantics that is used by <var>TypedArray</var>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>proto</var> be ?&nbsp;<emu-xref aoid="GetPrototypeFromConstructor" id="_ref_13902"><a href="ordinary-and-exotic-objects-behaviours.html#sec-getprototypefromconstructor" class="e-user-code">GetPrototypeFromConstructor</a></emu-xref>(<var>newTarget</var>, <var>defaultProto</var>).</li><li>Let <var>obj</var> be <emu-xref aoid="TypedArrayCreate" id="_ref_13903"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraycreate">TypedArrayCreate</a></emu-xref>(<var>proto</var>).</li><li><emu-xref href="#assert" id="_ref_13904"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>obj</var>.<var class="field">[[ViewedArrayBuffer]]</var> is <emu-val>undefined</emu-val>.</li><li>Set <var>obj</var>.<var class="field">[[TypedArrayName]]</var> to <var>constructorName</var>.</li><li>If <var>constructorName</var> is either <emu-val>"BigInt64Array"</emu-val> or <emu-val>"BigUint64Array"</emu-val>, set <var>obj</var>.<var class="field">[[ContentType]]</var> to <emu-const>bigint</emu-const>.</li><li>Else, set <var>obj</var>.<var class="field">[[ContentType]]</var> to <emu-const>number</emu-const>.</li><li>If <var>length</var> is not present, then<ol><li>Set <var>obj</var>.<var class="field">[[ByteLength]]</var> to 0.</li><li>Set <var>obj</var>.<var class="field">[[ByteOffset]]</var> to 0.</li><li>Set <var>obj</var>.<var class="field">[[ArrayLength]]</var> to 0.</li></ol></li><li>Else,<ol><li>Perform ?&nbsp;<emu-xref aoid="AllocateTypedArrayBuffer" id="_ref_13905"><a href="indexed-collections.html#sec-allocatetypedarraybuffer">AllocateTypedArrayBuffer</a></emu-xref>(<var>obj</var>, <var>length</var>).</li></ol></li><li>Return <var>obj</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-initializetypedarrayfromtypedarray" type="abstract operation" oldids="sec-typedarray-typedarray" aoid="InitializeTypedArrayFromTypedArray"><span id="sec-typedarray-typedarray"></span>
<h1><span class="secnum">23.2.5.1.2</span> InitializeTypedArrayFromTypedArray ( <var>O</var>, <var>srcArray</var> )</h1>
<p>The abstract operation InitializeTypedArrayFromTypedArray takes arguments <var>O</var> (a <emu-xref href="#typedarray" id="_ref_13906"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and <var>srcArray</var> (a <emu-xref href="#typedarray" id="_ref_13907"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13908"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> <emu-const>unused</emu-const> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13909"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>srcData</var> be <var>srcArray</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Let <var>elementType</var> be <emu-xref aoid="TypedArrayElementType" id="_ref_13910"><a href="indexed-collections.html#sec-typedarrayelementtype">TypedArrayElementType</a></emu-xref>(<var>O</var>).</li><li>Let <var>elementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13911"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>O</var>).</li><li>Let <var>srcType</var> be <emu-xref aoid="TypedArrayElementType" id="_ref_13912"><a href="indexed-collections.html#sec-typedarrayelementtype">TypedArrayElementType</a></emu-xref>(<var>srcArray</var>).</li><li>Let <var>srcElementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13913"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>srcArray</var>).</li><li>Let <var>srcByteOffset</var> be <var>srcArray</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Let <var>srcRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13914"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>srcArray</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13915"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>srcRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>elementLength</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13916"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>srcRecord</var>).</li><li>Let <var>byteLength</var> be <var>elementSize</var> × <var>elementLength</var>.</li><li>If <var>elementType</var> is <var>srcType</var>, then<ol><li>Let <var>data</var> be ?&nbsp;<emu-xref aoid="CloneArrayBuffer" id="_ref_13917"><a href="structured-data.html#sec-clonearraybuffer">CloneArrayBuffer</a></emu-xref>(<var>srcData</var>, <var>srcByteOffset</var>, <var>byteLength</var>).</li></ol></li><li>Else,<ol><li>Let <var>data</var> be ?&nbsp;<emu-xref aoid="AllocateArrayBuffer" id="_ref_13918"><a href="structured-data.html#sec-allocatearraybuffer">AllocateArrayBuffer</a></emu-xref>(<emu-xref href="#sec-arraybuffer-constructor" id="_ref_13919"><a href="structured-data.html#sec-arraybuffer-constructor">%ArrayBuffer%</a></emu-xref>, <var>byteLength</var>).</li><li>If <var>srcArray</var>.<var class="field">[[ContentType]]</var> is not <var>O</var>.<var class="field">[[ContentType]]</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>srcByteIndex</var> be <var>srcByteOffset</var>.</li><li>Let <var>targetByteIndex</var> be 0.</li><li>Let <var>count</var> be <var>elementLength</var>.</li><li>Repeat, while <var>count</var> &gt; 0,<ol><li>Let <var>value</var> be <emu-xref aoid="GetValueFromBuffer" id="_ref_13920"><a href="structured-data.html#sec-getvaluefrombuffer">GetValueFromBuffer</a></emu-xref>(<var>srcData</var>, <var>srcByteIndex</var>, <var>srcType</var>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Perform <emu-xref aoid="SetValueInBuffer" id="_ref_13921"><a href="structured-data.html#sec-setvalueinbuffer">SetValueInBuffer</a></emu-xref>(<var>data</var>, <var>targetByteIndex</var>, <var>elementType</var>, <var>value</var>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Set <var>srcByteIndex</var> to <var>srcByteIndex</var> + <var>srcElementSize</var>.</li><li>Set <var>targetByteIndex</var> to <var>targetByteIndex</var> + <var>elementSize</var>.</li><li>Set <var>count</var> to <var>count</var> - 1.</li></ol></li></ol></li><li>Set <var>O</var>.<var class="field">[[ViewedArrayBuffer]]</var> to <var>data</var>.</li><li>Set <var>O</var>.<var class="field">[[ByteLength]]</var> to <var>byteLength</var>.</li><li>Set <var>O</var>.<var class="field">[[ByteOffset]]</var> to 0.</li><li>Set <var>O</var>.<var class="field">[[ArrayLength]]</var> to <var>elementLength</var>.</li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-initializetypedarrayfromarraybuffer" type="abstract operation" oldids="sec-typedarray-buffer-byteoffset-length" aoid="InitializeTypedArrayFromArrayBuffer"><span id="sec-typedarray-buffer-byteoffset-length"></span>
<h1><span class="secnum">23.2.5.1.3</span> InitializeTypedArrayFromArrayBuffer ( <var>O</var>, <var>buffer</var>, <var>byteOffset</var>, <var>length</var> )</h1>
<p>The abstract operation InitializeTypedArrayFromArrayBuffer takes arguments <var>O</var> (a <emu-xref href="#typedarray" id="_ref_13922"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>), <var>buffer</var> (an ArrayBuffer or a SharedArrayBuffer), <var>byteOffset</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_13923"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>), and <var>length</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_13924"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13925"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> <emu-const>unused</emu-const> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13926"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>elementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13927"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>O</var>).</li><li>Let <var>offset</var> be ?&nbsp;<emu-xref aoid="ToIndex" id="_ref_13928"><a href="abstract-operations.html#sec-toindex" class="e-user-code">ToIndex</a></emu-xref>(<var>byteOffset</var>).</li><li>If <var>offset</var> <emu-xref aoid="modulo" id="_ref_13929"><a href="notational-conventions.html#eqn-modulo">modulo</a></emu-xref> <var>elementSize</var> ≠ 0, throw a <emu-val>RangeError</emu-val> exception.</li><li>Let <var>bufferIsFixedLength</var> be <emu-xref aoid="IsFixedLengthArrayBuffer" id="_ref_13930"><a href="structured-data.html#sec-isfixedlengtharraybuffer">IsFixedLengthArrayBuffer</a></emu-xref>(<var>buffer</var>).</li><li>If <var>length</var> is not <emu-val>undefined</emu-val>, then<ol><li>Let <var>newLength</var> be ?&nbsp;<emu-xref aoid="ToIndex" id="_ref_13931"><a href="abstract-operations.html#sec-toindex" class="e-user-code">ToIndex</a></emu-xref>(<var>length</var>).</li></ol></li><li>If <emu-xref aoid="IsDetachedBuffer" id="_ref_13932"><a href="structured-data.html#sec-isdetachedbuffer">IsDetachedBuffer</a></emu-xref>(<var>buffer</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>bufferByteLength</var> be <emu-xref aoid="ArrayBufferByteLength" id="_ref_13933"><a href="structured-data.html#sec-arraybufferbytelength">ArrayBufferByteLength</a></emu-xref>(<var>buffer</var>, <emu-const>seq-cst</emu-const>).</li><li>If <var>length</var> is <emu-val>undefined</emu-val> and <var>bufferIsFixedLength</var> is <emu-val>false</emu-val>, then<ol><li>If <var>offset</var> &gt; <var>bufferByteLength</var>, throw a <emu-val>RangeError</emu-val> exception.</li><li>Set <var>O</var>.<var class="field">[[ByteLength]]</var> to <emu-const>auto</emu-const>.</li><li>Set <var>O</var>.<var class="field">[[ArrayLength]]</var> to <emu-const>auto</emu-const>.</li></ol></li><li>Else,<ol><li>If <var>length</var> is <emu-val>undefined</emu-val>, then<ol><li>If <var>bufferByteLength</var> <emu-xref aoid="modulo" id="_ref_13934"><a href="notational-conventions.html#eqn-modulo">modulo</a></emu-xref> <var>elementSize</var> ≠ 0, throw a <emu-val>RangeError</emu-val> exception.</li><li>Let <var>newByteLength</var> be <var>bufferByteLength</var> - <var>offset</var>.</li><li>If <var>newByteLength</var> &lt; 0, throw a <emu-val>RangeError</emu-val> exception.</li></ol></li><li>Else,<ol><li>Let <var>newByteLength</var> be <var>newLength</var> × <var>elementSize</var>.</li><li>If <var>offset</var> + <var>newByteLength</var> &gt; <var>bufferByteLength</var>, throw a <emu-val>RangeError</emu-val> exception.</li></ol></li><li>Set <var>O</var>.<var class="field">[[ByteLength]]</var> to <var>newByteLength</var>.</li><li>Set <var>O</var>.<var class="field">[[ArrayLength]]</var> to <var>newByteLength</var> / <var>elementSize</var>.</li></ol></li><li>Set <var>O</var>.<var class="field">[[ViewedArrayBuffer]]</var> to <var>buffer</var>.</li><li>Set <var>O</var>.<var class="field">[[ByteOffset]]</var> to <var>offset</var>.</li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-initializetypedarrayfromlist" type="abstract operation" aoid="InitializeTypedArrayFromList">
<h1><span class="secnum">23.2.5.1.4</span> InitializeTypedArrayFromList ( <var>O</var>, <var>values</var> )</h1>
<p>The abstract operation InitializeTypedArrayFromList takes arguments <var>O</var> (a <emu-xref href="#typedarray" id="_ref_13935"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and <var>values</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_13936"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-ecmascript-language-types" id="_ref_13937"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language values</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13938"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> <emu-const>unused</emu-const> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13939"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>len</var> be the number of elements in <var>values</var>.</li><li>Perform ?&nbsp;<emu-xref aoid="AllocateTypedArrayBuffer" id="_ref_13940"><a href="indexed-collections.html#sec-allocatetypedarraybuffer">AllocateTypedArrayBuffer</a></emu-xref>(<var>O</var>, <var>len</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13941"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13942"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be the first element of <var>values</var>.</li><li>Remove the first element from <var>values</var>.</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13943"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>Pk</var>, <var>kValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li><emu-xref href="#assert" id="_ref_13944"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>values</var> is now an empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_13945"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-initializetypedarrayfromarraylike" type="abstract operation" aoid="InitializeTypedArrayFromArrayLike">
<h1><span class="secnum">23.2.5.1.5</span> InitializeTypedArrayFromArrayLike ( <var>O</var>, <var>arrayLike</var> )</h1>
<p>The abstract operation InitializeTypedArrayFromArrayLike takes arguments <var>O</var> (a <emu-xref href="#typedarray" id="_ref_13946"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and <var>arrayLike</var> (an Object, but not a <emu-xref href="#typedarray" id="_ref_13947"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref> or an ArrayBuffer) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13948"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> <emu-const>unused</emu-const> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13949"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_13950"><a href="abstract-operations.html#sec-lengthofarraylike" class="e-user-code">LengthOfArrayLike</a></emu-xref>(<var>arrayLike</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="AllocateTypedArrayBuffer" id="_ref_13951"><a href="indexed-collections.html#sec-allocatetypedarraybuffer">AllocateTypedArrayBuffer</a></emu-xref>(<var>O</var>, <var>len</var>).</li><li>Let <var>k</var> be 0.</li><li>Repeat, while <var>k</var> &lt; <var>len</var>,<ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_13952"><a href="abstract-operations.html#sec-tostring">ToString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_13953"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>k</var>)).</li><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13954"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>arrayLike</var>, <var>Pk</var>).</li><li>Perform ?&nbsp;<emu-xref aoid="Set" id="_ref_13955"><a href="abstract-operations.html#sec-set-o-p-v-throw" class="e-user-code">Set</a></emu-xref>(<var>O</var>, <var>Pk</var>, <var>kValue</var>, <emu-val>true</emu-val>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-allocatetypedarraybuffer" type="abstract operation" aoid="AllocateTypedArrayBuffer">
<h1><span class="secnum">23.2.5.1.6</span> AllocateTypedArrayBuffer ( <var>O</var>, <var>length</var> )</h1>
<p>The abstract operation AllocateTypedArrayBuffer takes arguments <var>O</var> (a <emu-xref href="#typedarray" id="_ref_13956"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArray</a></emu-xref>) and <var>length</var> (a non-negative <emu-xref href="#integer" id="_ref_13957"><a href="notational-conventions.html#integer">integer</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13958"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> <emu-const>unused</emu-const> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_13959"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It allocates and associates an ArrayBuffer with <var>O</var>. It performs the following steps when called:</p>
<emu-alg><ol><li><emu-xref href="#assert" id="_ref_13960"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>O</var>.<var class="field">[[ViewedArrayBuffer]]</var> is <emu-val>undefined</emu-val>.</li><li>Let <var>elementSize</var> be <emu-xref aoid="TypedArrayElementSize" id="_ref_13961"><a href="indexed-collections.html#sec-typedarrayelementsize">TypedArrayElementSize</a></emu-xref>(<var>O</var>).</li><li>Let <var>byteLength</var> be <var>elementSize</var> × <var>length</var>.</li><li>Let <var>data</var> be ?&nbsp;<emu-xref aoid="AllocateArrayBuffer" id="_ref_13962"><a href="structured-data.html#sec-allocatearraybuffer">AllocateArrayBuffer</a></emu-xref>(<emu-xref href="#sec-arraybuffer-constructor" id="_ref_13963"><a href="structured-data.html#sec-arraybuffer-constructor">%ArrayBuffer%</a></emu-xref>, <var>byteLength</var>).</li><li>Set <var>O</var>.<var class="field">[[ViewedArrayBuffer]]</var> to <var>data</var>.</li><li>Set <var>O</var>.<var class="field">[[ByteLength]]</var> to <var>byteLength</var>.</li><li>Set <var>O</var>.<var class="field">[[ByteOffset]]</var> to 0.</li><li>Set <var>O</var>.<var class="field">[[ArrayLength]]</var> to <var>length</var>.</li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-the-typedarray-constructors">
<h1><span class="secnum">23.2.6</span> Properties of the <var>TypedArray</var> Constructors</h1>
<p>Each <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13964"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref>:</p>
<ul>
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-%typedarray%-intrinsic-object" id="_ref_13965"><a href="indexed-collections.html#sec-%typedarray%-intrinsic-object">%TypedArray%</a></emu-xref>.</li>
<li>has a <emu-val>"length"</emu-val> property whose value is <emu-val>3</emu-val><sub>𝔽</sub>.</li>
<li>has a <emu-val>"name"</emu-val> property whose value is the String value of the <emu-xref href="#constructor" id="_ref_13966"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> name specified for it in <emu-xref href="#table-the-typedarray-constructors" id="_ref_773"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref>.</li>
<li>has the following properties:</li>
</ul>
<emu-clause id="sec-typedarray.bytes_per_element">
<h1><span class="secnum">23.2.6.1</span> <var>TypedArray</var>.BYTES_PER_ELEMENT</h1>
<p>The value of <var>TypedArray</var><code>.BYTES_PER_ELEMENT</code> is the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors" id="_ref_774"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref> for <var>TypedArray</var>.</p>
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
</emu-clause>
<emu-clause id="sec-typedarray.prototype">
<h1><span class="secnum">23.2.6.2</span> <var>TypedArray</var>.prototype</h1>
<p>The initial value of <var>TypedArray</var><code>.prototype</code> is the corresponding <var>TypedArray</var> prototype intrinsic object (<emu-xref href="#sec-properties-of-typedarray-prototype-objects" id="_ref_775"><a href="indexed-collections.html#sec-properties-of-typedarray-prototype-objects">23.2.7</a></emu-xref>).</p>
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-typedarray-prototype-objects">
<h1><span class="secnum">23.2.7</span> Properties of the <var>TypedArray</var> Prototype Objects</h1>
<p>Each <var>TypedArray</var> prototype object:</p>
<ul>
<li>has a <var class="field">[[Prototype]]</var> internal slot whose value is <emu-xref href="#sec-properties-of-the-%typedarrayprototype%-object" id="_ref_13967"><a href="indexed-collections.html#sec-properties-of-the-%typedarrayprototype%-object">%TypedArray.prototype%</a></emu-xref>.</li>
<li>is an <emu-xref href="#ordinary-object" id="_ref_13968"><a href="ecmascript-data-types-and-values.html#ordinary-object">ordinary object</a></emu-xref>.</li>
<li>does not have a <var class="field">[[ViewedArrayBuffer]]</var> or any other of the internal slots that are specific to <var>TypedArray</var> instance objects.</li>
</ul>
<emu-clause id="sec-typedarray.prototype.bytes_per_element">
<h1><span class="secnum">23.2.7.1</span> <var>TypedArray</var>.prototype.BYTES_PER_ELEMENT</h1>
<p>The value of <var>TypedArray</var><code>.prototype.BYTES_PER_ELEMENT</code> is the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors" id="_ref_776"><a href="indexed-collections.html#table-the-typedarray-constructors">Table 70</a></emu-xref> for <var>TypedArray</var>.</p>
<p>This property has the attributes { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Enumerable]]</var>: <emu-val>false</emu-val>, <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> }.</p>
</emu-clause>
<emu-clause id="sec-typedarray.prototype.constructor">
<h1><span class="secnum">23.2.7.2</span> <var>TypedArray</var>.prototype.constructor</h1>
<p>The initial value of the <emu-val>"constructor"</emu-val> property of the prototype for a given <var>TypedArray</var> <emu-xref href="#constructor" id="_ref_13969"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> is the <emu-xref href="#constructor" id="_ref_13970"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> itself.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-typedarray-instances">
<h1><span class="secnum">23.2.8</span> Properties of <var>TypedArray</var> Instances</h1>
<p><var>TypedArray</var> instances are <emu-xref href="#typedarray" id="_ref_13971"><a href="ordinary-and-exotic-objects-behaviours.html#typedarray">TypedArrays</a></emu-xref>. Each <var>TypedArray</var> instance inherits properties from the corresponding <var>TypedArray</var> prototype object. Each <var>TypedArray</var> instance has the following internal slots: <var class="field">[[ViewedArrayBuffer]]</var>, <var class="field">[[TypedArrayName]]</var>, <var class="field">[[ContentType]]</var>, <var class="field">[[ByteLength]]</var>, <var class="field">[[ByteOffset]]</var>, and <var class="field">[[ArrayLength]]</var>.</p>
</emu-clause>
</emu-clause>
<emu-clause id="sec-uint8array">
<h1><span class="secnum">23.3</span> Uint8Array Objects</h1>
<p>A Uint8Array is a particular kind of <var>TypedArray</var> as described above. In addition, there are additional methods on the Uint8Array <emu-xref href="#constructor" id="_ref_13972"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> (<emu-xref href="#sec-additional-properties-of-the-uint8array-constructor" id="_ref_777"><a href="indexed-collections.html#sec-additional-properties-of-the-uint8array-constructor">23.3.1</a></emu-xref>) and on the Uint8Array prototype object (<emu-xref href="#sec-additional-properties-of-the-uint8array-prototype-object" id="_ref_778"><a href="indexed-collections.html#sec-additional-properties-of-the-uint8array-prototype-object">23.3.2</a></emu-xref>).</p>
<emu-clause id="sec-additional-properties-of-the-uint8array-constructor">
<h1><span class="secnum">23.3.1</span> Additional Properties of the Uint8Array Constructor</h1>
<emu-clause id="sec-uint8array.frombase64" type="built-in function">
<h1><span class="secnum">23.3.1.1</span> Uint8Array.fromBase64 ( <var>string</var> [ , <var>options</var> ] )</h1>
<emu-alg><ol><li>If <var>string</var> <emu-xref href="#sec-ecmascript-language-types-string-type" id="_ref_13973"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-string-type">is not a String</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>opts</var> be ?&nbsp;<emu-xref aoid="GetOptionsObject" id="_ref_13974"><a href="abstract-operations.html#sec-getoptionsobject">GetOptionsObject</a></emu-xref>(<var>options</var>).</li><li>Let <var>alphabet</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13975"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>opts</var>, <emu-val>"alphabet"</emu-val>).</li><li>If <var>alphabet</var> is <emu-val>undefined</emu-val>, set <var>alphabet</var> to <emu-val>"base64"</emu-val>.</li><li>If <var>alphabet</var> is neither <emu-val>"base64"</emu-val> nor <emu-val>"base64url"</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>lastChunkHandling</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13976"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>opts</var>, <emu-val>"lastChunkHandling"</emu-val>).</li><li>If <var>lastChunkHandling</var> is <emu-val>undefined</emu-val>, set <var>lastChunkHandling</var> to <emu-val>"loose"</emu-val>.</li><li>If <var>lastChunkHandling</var> is not one of <emu-val>"loose"</emu-val>, <emu-val>"strict"</emu-val>, or <emu-val>"stop-before-partial"</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>result</var> be <emu-xref aoid="FromBase64" id="_ref_13977"><a href="indexed-collections.html#sec-frombase64">FromBase64</a></emu-xref>(<var>string</var>, <var>alphabet</var>, <var>lastChunkHandling</var>).</li><li>If <var>result</var>.<var class="field">[[Error]]</var> is not <emu-const>none</emu-const>, then<ol><li>Return <emu-xref aoid="ThrowCompletion" id="_ref_13978"><a href="ecmascript-data-types-and-values.html#sec-throwcompletion">ThrowCompletion</a></emu-xref>(<var>result</var>.<var class="field">[[Error]]</var>).</li></ol></li><li>Let <var>resultLength</var> be the number of elements in <var>result</var>.<var class="field">[[Bytes]]</var>.</li><li>Let <var>ta</var> be ?&nbsp;<emu-xref aoid="AllocateTypedArray" id="_ref_13979"><a href="indexed-collections.html#sec-allocatetypedarray">AllocateTypedArray</a></emu-xref>(<emu-val>"Uint8Array"</emu-val>, <emu-xref href="#sec-typedarray-objects" id="_ref_13980"><a href="indexed-collections.html#sec-typedarray-objects">%Uint8Array%</a></emu-xref>, <emu-val>"%Uint8Array.prototype%"</emu-val>, <var>resultLength</var>).</li><li><emu-xref href="#assert" id="_ref_13981"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>ta</var>.<var class="field">[[ViewedArrayBuffer]]</var>.<var class="field">[[ArrayBufferByteLength]]</var> is the number of elements in <var>result</var>.<var class="field">[[Bytes]]</var>.</li><li>Set the value at each index of <var>ta</var>.<var class="field">[[ViewedArrayBuffer]]</var>.<var class="field">[[ArrayBufferData]]</var> to the value at the corresponding index of <var>result</var>.<var class="field">[[Bytes]]</var>.</li><li>Return <var>ta</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-uint8array.fromhex" type="built-in function">
<h1><span class="secnum">23.3.1.2</span> Uint8Array.fromHex ( <var>string</var> )</h1>
<emu-alg><ol><li>If <var>string</var> <emu-xref href="#sec-ecmascript-language-types-string-type" id="_ref_13982"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-string-type">is not a String</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>result</var> be <emu-xref aoid="FromHex" id="_ref_13983"><a href="indexed-collections.html#sec-fromhex">FromHex</a></emu-xref>(<var>string</var>).</li><li>If <var>result</var>.<var class="field">[[Error]]</var> is not <emu-const>none</emu-const>, then<ol><li>Return <emu-xref aoid="ThrowCompletion" id="_ref_13984"><a href="ecmascript-data-types-and-values.html#sec-throwcompletion">ThrowCompletion</a></emu-xref>(<var>result</var>.<var class="field">[[Error]]</var>).</li></ol></li><li>Let <var>resultLength</var> be the number of elements in <var>result</var>.<var class="field">[[Bytes]]</var>.</li><li>Let <var>ta</var> be ?&nbsp;<emu-xref aoid="AllocateTypedArray" id="_ref_13985"><a href="indexed-collections.html#sec-allocatetypedarray">AllocateTypedArray</a></emu-xref>(<emu-val>"Uint8Array"</emu-val>, <emu-xref href="#sec-typedarray-objects" id="_ref_13986"><a href="indexed-collections.html#sec-typedarray-objects">%Uint8Array%</a></emu-xref>, <emu-val>"%Uint8Array.prototype%"</emu-val>, <var>resultLength</var>).</li><li><emu-xref href="#assert" id="_ref_13987"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>ta</var>.<var class="field">[[ViewedArrayBuffer]]</var>.<var class="field">[[ArrayBufferByteLength]]</var> is the number of elements in <var>result</var>.<var class="field">[[Bytes]]</var>.</li><li>Set the value at each index of <var>ta</var>.<var class="field">[[ViewedArrayBuffer]]</var>.<var class="field">[[ArrayBufferData]]</var> to the value at the corresponding index of <var>result</var>.<var class="field">[[Bytes]]</var>.</li><li>Return <var>ta</var>.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-additional-properties-of-the-uint8array-prototype-object">
<h1><span class="secnum">23.3.2</span> Additional Properties of the Uint8Array Prototype Object</h1>
<emu-clause id="sec-uint8array.prototype.setfrombase64" type="built-in function">
<h1><span class="secnum">23.3.2.1</span> Uint8Array.prototype.setFromBase64 ( <var>string</var> [ , <var>options</var> ] )</h1>
<emu-alg><ol><li>Let <var>into</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="ValidateUint8Array" id="_ref_13988"><a href="indexed-collections.html#sec-validateuint8array">ValidateUint8Array</a></emu-xref>(<var>into</var>).</li><li>If <var>string</var> <emu-xref href="#sec-ecmascript-language-types-string-type" id="_ref_13989"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-string-type">is not a String</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>opts</var> be ?&nbsp;<emu-xref aoid="GetOptionsObject" id="_ref_13990"><a href="abstract-operations.html#sec-getoptionsobject">GetOptionsObject</a></emu-xref>(<var>options</var>).</li><li>Let <var>alphabet</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13991"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>opts</var>, <emu-val>"alphabet"</emu-val>).</li><li>If <var>alphabet</var> is <emu-val>undefined</emu-val>, set <var>alphabet</var> to <emu-val>"base64"</emu-val>.</li><li>If <var>alphabet</var> is neither <emu-val>"base64"</emu-val> nor <emu-val>"base64url"</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>lastChunkHandling</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_13992"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>opts</var>, <emu-val>"lastChunkHandling"</emu-val>).</li><li>If <var>lastChunkHandling</var> is <emu-val>undefined</emu-val>, set <var>lastChunkHandling</var> to <emu-val>"loose"</emu-val>.</li><li>If <var>lastChunkHandling</var> is not one of <emu-val>"loose"</emu-val>, <emu-val>"strict"</emu-val>, or <emu-val>"stop-before-partial"</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>taRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_13993"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>into</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_13994"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>byteLength</var> be <emu-xref aoid="TypedArrayLength" id="_ref_13995"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>result</var> be <emu-xref aoid="FromBase64" id="_ref_13996"><a href="indexed-collections.html#sec-frombase64">FromBase64</a></emu-xref>(<var>string</var>, <var>alphabet</var>, <var>lastChunkHandling</var>, <var>byteLength</var>).</li><li>Let <var>bytes</var> be <var>result</var>.<var class="field">[[Bytes]]</var>.</li><li>Let <var>written</var> be the number of elements in <var>bytes</var>.</li><li>NOTE: <emu-xref aoid="FromBase64" id="_ref_13997"><a href="indexed-collections.html#sec-frombase64">FromBase64</a></emu-xref> does not invoke any user code, so the ArrayBuffer backing <var>into</var> cannot have been detached or shrunk.</li><li><emu-xref href="#assert" id="_ref_13998"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>written</var><var>byteLength</var>.</li><li>Perform <emu-xref aoid="SetUint8ArrayBytes" id="_ref_13999"><a href="indexed-collections.html#sec-setuint8arraybytes">SetUint8ArrayBytes</a></emu-xref>(<var>into</var>, <var>bytes</var>).</li><li>If <var>result</var>.<var class="field">[[Error]]</var> is not <emu-const>none</emu-const>, then<ol><li>Return <emu-xref aoid="ThrowCompletion" id="_ref_14000"><a href="ecmascript-data-types-and-values.html#sec-throwcompletion">ThrowCompletion</a></emu-xref>(<var>result</var>.<var class="field">[[Error]]</var>).</li></ol></li><li>Let <var>resultObject</var> be <emu-xref aoid="OrdinaryObjectCreate" id="_ref_14001"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinaryobjectcreate">OrdinaryObjectCreate</a></emu-xref>(<emu-xref href="#sec-properties-of-the-object-prototype-object" id="_ref_14002"><a href="fundamental-objects.html#sec-properties-of-the-object-prototype-object">%Object.prototype%</a></emu-xref>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_14003"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>resultObject</var>, <emu-val>"read"</emu-val>, <emu-xref aoid="𝔽" id="_ref_14004"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>result</var>.<var class="field">[[Read]]</var>)).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_14005"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>resultObject</var>, <emu-val>"written"</emu-val>, <emu-xref aoid="𝔽" id="_ref_14006"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>written</var>)).</li><li>Return <var>resultObject</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-uint8array.prototype.setfromhex" type="built-in function">
<h1><span class="secnum">23.3.2.2</span> Uint8Array.prototype.setFromHex ( <var>string</var> )</h1>
<emu-alg><ol><li>Let <var>into</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="ValidateUint8Array" id="_ref_14007"><a href="indexed-collections.html#sec-validateuint8array">ValidateUint8Array</a></emu-xref>(<var>into</var>).</li><li>If <var>string</var> <emu-xref href="#sec-ecmascript-language-types-string-type" id="_ref_14008"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-string-type">is not a String</a></emu-xref>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>taRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_14009"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>into</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_14010"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>byteLength</var> be <emu-xref aoid="TypedArrayLength" id="_ref_14011"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>result</var> be <emu-xref aoid="FromHex" id="_ref_14012"><a href="indexed-collections.html#sec-fromhex">FromHex</a></emu-xref>(<var>string</var>, <var>byteLength</var>).</li><li>Let <var>bytes</var> be <var>result</var>.<var class="field">[[Bytes]]</var>.</li><li>Let <var>written</var> be the number of elements in <var>bytes</var>.</li><li>NOTE: <emu-xref aoid="FromHex" id="_ref_14013"><a href="indexed-collections.html#sec-fromhex">FromHex</a></emu-xref> does not invoke any user code, so the ArrayBuffer backing <var>into</var> cannot have been detached or shrunk.</li><li><emu-xref href="#assert" id="_ref_14014"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>written</var><var>byteLength</var>.</li><li>Perform <emu-xref aoid="SetUint8ArrayBytes" id="_ref_14015"><a href="indexed-collections.html#sec-setuint8arraybytes">SetUint8ArrayBytes</a></emu-xref>(<var>into</var>, <var>bytes</var>).</li><li>If <var>result</var>.<var class="field">[[Error]]</var> is not <emu-const>none</emu-const>, then<ol><li>Return <emu-xref aoid="ThrowCompletion" id="_ref_14016"><a href="ecmascript-data-types-and-values.html#sec-throwcompletion">ThrowCompletion</a></emu-xref>(<var>result</var>.<var class="field">[[Error]]</var>).</li></ol></li><li>Let <var>resultObject</var> be <emu-xref aoid="OrdinaryObjectCreate" id="_ref_14017"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinaryobjectcreate">OrdinaryObjectCreate</a></emu-xref>(<emu-xref href="#sec-properties-of-the-object-prototype-object" id="_ref_14018"><a href="fundamental-objects.html#sec-properties-of-the-object-prototype-object">%Object.prototype%</a></emu-xref>).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_14019"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>resultObject</var>, <emu-val>"read"</emu-val>, <emu-xref aoid="𝔽" id="_ref_14020"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>result</var>.<var class="field">[[Read]]</var>)).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_14021"><a href="abstract-operations.html#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>resultObject</var>, <emu-val>"written"</emu-val>, <emu-xref aoid="𝔽" id="_ref_14022"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>written</var>)).</li><li>Return <var>resultObject</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-uint8array.prototype.tobase64" type="built-in function">
<h1><span class="secnum">23.3.2.3</span> Uint8Array.prototype.toBase64 ( [ <var>options</var> ] )</h1>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="ValidateUint8Array" id="_ref_14023"><a href="indexed-collections.html#sec-validateuint8array">ValidateUint8Array</a></emu-xref>(<var>O</var>).</li><li>Let <var>opts</var> be ?&nbsp;<emu-xref aoid="GetOptionsObject" id="_ref_14024"><a href="abstract-operations.html#sec-getoptionsobject">GetOptionsObject</a></emu-xref>(<var>options</var>).</li><li>Let <var>alphabet</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_14025"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>opts</var>, <emu-val>"alphabet"</emu-val>).</li><li>If <var>alphabet</var> is <emu-val>undefined</emu-val>, set <var>alphabet</var> to <emu-val>"base64"</emu-val>.</li><li>If <var>alphabet</var> is neither <emu-val>"base64"</emu-val> nor <emu-val>"base64url"</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>omitPadding</var> be <emu-xref aoid="ToBoolean" id="_ref_14026"><a href="abstract-operations.html#sec-toboolean">ToBoolean</a></emu-xref>(? <emu-xref aoid="Get" id="_ref_14027"><a href="abstract-operations.html#sec-get-o-p" class="e-user-code">Get</a></emu-xref>(<var>opts</var>, <emu-val>"omitPadding"</emu-val>)).</li><li>Let <var>toEncode</var> be ?&nbsp;<emu-xref aoid="GetUint8ArrayBytes" id="_ref_14028"><a href="indexed-collections.html#sec-getuint8arraybytes">GetUint8ArrayBytes</a></emu-xref>(<var>O</var>).</li><li>If <var>alphabet</var> is <emu-val>"base64"</emu-val>, then<ol><li>Let <var>outAscii</var> be the sequence of code points which results from encoding <var>toEncode</var> according to the base64 encoding specified in section 4 of <a href="https://datatracker.ietf.org/doc/html/rfc4648">RFC 4648</a>. Padding is included if and only if <var>omitPadding</var> is <emu-val>false</emu-val>.</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_14029"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>alphabet</var> is <emu-val>"base64url"</emu-val>.</li><li>Let <var>outAscii</var> be the sequence of code points which results from encoding <var>toEncode</var> according to the base64url encoding specified in section 5 of <a href="https://datatracker.ietf.org/doc/html/rfc4648">RFC 4648</a>. Padding is included if and only if <var>omitPadding</var> is <emu-val>false</emu-val>.</li></ol></li><li>Return <emu-xref aoid="CodePointsToString" id="_ref_14030"><a href="ecmascript-language-source-code.html#sec-codepointstostring">CodePointsToString</a></emu-xref>(<var>outAscii</var>).</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-uint8array.prototype.tohex" type="built-in function">
<h1><span class="secnum">23.3.2.4</span> Uint8Array.prototype.toHex ( )</h1>
<emu-alg><ol><li>Let <var>O</var> be the <emu-val>this</emu-val> value.</li><li>Perform ?&nbsp;<emu-xref aoid="ValidateUint8Array" id="_ref_14031"><a href="indexed-collections.html#sec-validateuint8array">ValidateUint8Array</a></emu-xref>(<var>O</var>).</li><li>Let <var>toEncode</var> be ?&nbsp;<emu-xref aoid="GetUint8ArrayBytes" id="_ref_14032"><a href="indexed-collections.html#sec-getuint8arraybytes">GetUint8ArrayBytes</a></emu-xref>(<var>O</var>).</li><li>Let <var>out</var> be the empty String.</li><li>For each byte <var>byte</var> of <var>toEncode</var>, do<ol><li>Let <var>hex</var> be <emu-xref aoid="Number::toString" id="_ref_14033"><a href="ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring">Number::toString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_14034"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>byte</var>), 16).</li><li>Set <var>hex</var> to <emu-xref aoid="StringPad" id="_ref_14035"><a href="text-processing.html#sec-stringpad">StringPad</a></emu-xref>(<var>hex</var>, 2, <emu-val>"0"</emu-val>, <emu-const>start</emu-const>).</li><li>Set <var>out</var> to the <emu-xref href="#string-concatenation" id="_ref_14036"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>out</var> and <var>hex</var>.</li></ol></li><li>Return <var>out</var>.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-abstract-operations-for-uint8array-objects">
<h1><span class="secnum">23.3.3</span> Abstract Operations for Uint8Array Objects</h1>
<emu-clause id="sec-validateuint8array" type="abstract operation" aoid="ValidateUint8Array">
<h1><span class="secnum">23.3.3.1</span> ValidateUint8Array ( <var>ta</var> )</h1>
<p>The abstract operation ValidateUint8Array takes argument <var>ta</var> (an <emu-xref href="#sec-ecmascript-language-types" id="_ref_14037"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types">ECMAScript language value</a></emu-xref>) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14038"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> <emu-const>unused</emu-const> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14039"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Perform ?&nbsp;<emu-xref aoid="RequireInternalSlot" id="_ref_14040"><a href="ordinary-and-exotic-objects-behaviours.html#sec-requireinternalslot">RequireInternalSlot</a></emu-xref>(<var>ta</var>, <var class="field">[[TypedArrayName]]</var>).</li><li>If <var>ta</var>.<var class="field">[[TypedArrayName]]</var> is not <emu-val>"Uint8Array"</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-getuint8arraybytes" type="abstract operation" aoid="GetUint8ArrayBytes">
<h1><span class="secnum">23.3.3.2</span> GetUint8ArrayBytes ( <var>ta</var> )</h1>
<p>The abstract operation GetUint8ArrayBytes takes argument <var>ta</var> (a Uint8Array) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14041"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14042"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-data-blocks" id="_ref_14043"><a href="ecmascript-data-types-and-values.html#sec-data-blocks">byte values</a></emu-xref> or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14044"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>buffer</var> be <var>ta</var>.<var class="field">[[ViewedArrayBuffer]]</var>.</li><li>Let <var>taRecord</var> be <emu-xref aoid="MakeTypedArrayWithBufferWitnessRecord" id="_ref_14045"><a href="ordinary-and-exotic-objects-behaviours.html#sec-maketypedarraywithbufferwitnessrecord">MakeTypedArrayWithBufferWitnessRecord</a></emu-xref>(<var>ta</var>, <emu-const>seq-cst</emu-const>).</li><li>If <emu-xref aoid="IsTypedArrayOutOfBounds" id="_ref_14046"><a href="ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds">IsTypedArrayOutOfBounds</a></emu-xref>(<var>taRecord</var>) is <emu-val>true</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>len</var> be <emu-xref aoid="TypedArrayLength" id="_ref_14047"><a href="ordinary-and-exotic-objects-behaviours.html#sec-typedarraylength">TypedArrayLength</a></emu-xref>(<var>taRecord</var>).</li><li>Let <var>byteOffset</var> be <var>ta</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Let <var>bytes</var> be a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14048"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> &lt; <var>len</var>,<ol><li>Let <var>byteIndex</var> be <var>byteOffset</var> + <var>index</var>.</li><li>Let <var>byte</var> be <emu-xref aoid="" id="_ref_14049"><a href="notational-conventions.html#%E2%84%9D"></a></emu-xref>(<emu-xref aoid="GetValueFromBuffer" id="_ref_14050"><a href="structured-data.html#sec-getvaluefrombuffer">GetValueFromBuffer</a></emu-xref>(<var>buffer</var>, <var>byteIndex</var>, <emu-const>uint8</emu-const>, <emu-val>true</emu-val>, <emu-const>unordered</emu-const>)).</li><li>Append <var>byte</var> to <var>bytes</var>.</li><li>Set <var>index</var> to <var>index</var> + 1.</li></ol></li><li>Return <var>bytes</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-setuint8arraybytes" type="abstract operation" aoid="SetUint8ArrayBytes">
<h1><span class="secnum">23.3.3.3</span> SetUint8ArrayBytes ( <var>into</var>, <var>bytes</var> )</h1>
<p>The abstract operation SetUint8ArrayBytes takes arguments <var>into</var> (a Uint8Array) and <var>bytes</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14051"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-data-blocks" id="_ref_14052"><a href="ecmascript-data-types-and-values.html#sec-data-blocks">byte values</a></emu-xref>) and returns <emu-const>unused</emu-const>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>offset</var> be <var>into</var>.<var class="field">[[ByteOffset]]</var>.</li><li>Let <var>len</var> be the number of elements in <var>bytes</var>.</li><li>Let <var>index</var> be 0.</li><li>Repeat, while <var>index</var> &lt; <var>len</var>,<ol><li>Let <var>byte</var> be <var>bytes</var>[<var>index</var>].</li><li>Let <var>byteIndexInBuffer</var> be <var>index</var> + <var>offset</var>.</li><li>Perform <emu-xref aoid="SetValueInBuffer" id="_ref_14053"><a href="structured-data.html#sec-setvalueinbuffer">SetValueInBuffer</a></emu-xref>(<var>into</var>.<var class="field">[[ViewedArrayBuffer]]</var>, <var>byteIndexInBuffer</var>, <emu-const>uint8</emu-const>, <emu-xref aoid="𝔽" id="_ref_14054"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>byte</var>), <emu-val>true</emu-val>, <emu-const>unordered</emu-const>).</li><li>Set <var>index</var> to <var>index</var> + 1.</li></ol></li><li>Return <emu-const>unused</emu-const>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-skipasciiwhitespace" type="abstract operation" aoid="SkipAsciiWhitespace">
<h1><span class="secnum">23.3.3.4</span> SkipAsciiWhitespace ( <var>string</var>, <var>index</var> )</h1>
<p>The abstract operation SkipAsciiWhitespace takes arguments <var>string</var> (a String) and <var>index</var> (a non-negative <emu-xref href="#integer" id="_ref_14055"><a href="notational-conventions.html#integer">integer</a></emu-xref>) and returns a non-negative <emu-xref href="#integer" id="_ref_14056"><a href="notational-conventions.html#integer">integer</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>length</var> be the length of <var>string</var>.</li><li>Repeat, while <var>index</var> &lt; <var>length</var>,<ol><li>Let <var>char</var> be the code unit at index <var>index</var> within <var>string</var>.</li><li>If <var>char</var> is not one of 0x0009 (TAB), 0x000A (LF), 0x000C (FF), 0x000D (CR), or 0x0020 (SPACE), then<ol><li>Return <var>index</var>.</li></ol></li><li>Set <var>index</var> to <var>index</var> + 1.</li></ol></li><li>Return <var>index</var>.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-decodefinalbase64chunk" type="abstract operation" aoid="DecodeFinalBase64Chunk">
<h1><span class="secnum">23.3.3.5</span> DecodeFinalBase64Chunk ( <var>chunk</var>, <var>throwOnExtraBits</var> )</h1>
<p>The abstract operation DecodeFinalBase64Chunk takes arguments <var>chunk</var> (a String of length 2 or 3) and <var>throwOnExtraBits</var> (a Boolean) and returns either a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14057"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">normal completion containing</a></emu-xref> a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14058"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-data-blocks" id="_ref_14059"><a href="ecmascript-data-types-and-values.html#sec-data-blocks">byte values</a></emu-xref>, or a <emu-xref href="#sec-completion-record-specification-type" id="_ref_14060"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">throw completion</a></emu-xref>. It performs the following steps when called:</p>
<emu-alg><ol><li>Let <var>chunkLength</var> be the length of <var>chunk</var>.</li><li>If <var>chunkLength</var> = 2, then<ol><li>Set <var>chunk</var> to the <emu-xref href="#string-concatenation" id="_ref_14061"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>chunk</var> and <emu-val>"AA"</emu-val>.</li></ol></li><li>Else,<ol><li><emu-xref href="#assert" id="_ref_14062"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>chunkLength</var> is 3.</li><li>Set <var>chunk</var> to the <emu-xref href="#string-concatenation" id="_ref_14063"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>chunk</var> and <emu-val>"A"</emu-val>.</li></ol></li><li>Let <var>bytes</var> be <emu-xref aoid="DecodeFullLengthBase64Chunk" id="_ref_14064"><a href="indexed-collections.html#sec-decodefulllengthbase64chunk">DecodeFullLengthBase64Chunk</a></emu-xref>(<var>chunk</var>).</li><li>If <var>chunkLength</var> = 2, then<ol><li>If <var>throwOnExtraBits</var> is <emu-val>true</emu-val> and <var>bytes</var>[1] ≠ 0, throw a <emu-val>SyntaxError</emu-val> exception.</li><li>Return « <var>bytes</var>[0]&nbsp;».</li></ol></li><li>If <var>throwOnExtraBits</var> is <emu-val>true</emu-val> and <var>bytes</var>[2] ≠ 0, throw a <emu-val>SyntaxError</emu-val> exception.</li><li>Return « <var>bytes</var>[0], <var>bytes</var>[1]&nbsp;».</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-decodefulllengthbase64chunk" type="abstract operation" aoid="DecodeFullLengthBase64Chunk">
<h1><span class="secnum">23.3.3.6</span> DecodeFullLengthBase64Chunk ( <var>chunk</var> )</h1>
<p>The abstract operation DecodeFullLengthBase64Chunk takes argument <var>chunk</var> (a String of length 4) and returns a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14065"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-data-blocks" id="_ref_14066"><a href="ecmascript-data-types-and-values.html#sec-data-blocks">byte values</a></emu-xref> of length 3.</p>
<p>The <dfn id="standard-base64-alphabet" tabindex="-1">standard base64 alphabet</dfn> is <emu-val>"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"</emu-val>, i.e., the String whose elements are the code units corresponding to every letter and number in the Unicode Basic Latin block along with <emu-val>"+"</emu-val> and <emu-val>"/"</emu-val>.</p>
<emu-alg><ol><li>Let <var>byteSequence</var> be the unique sequence of 3 bytes resulting from decoding <var>chunk</var> as base64 (i.e., the sequence such that applying the base64 encoding specified in section 4 of <a href="https://datatracker.ietf.org/doc/html/rfc4648">RFC 4648</a> to <var>byteSequence</var> would produce <var>chunk</var>).</li><li>Return a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14067"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> whose elements are the elements of <var>byteSequence</var>, in order.</li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-frombase64" type="abstract operation" aoid="FromBase64">
<h1><span class="secnum">23.3.3.7</span> FromBase64 ( <var>string</var>, <var>alphabet</var>, <var>lastChunkHandling</var> [ , <var>maxLength</var> ] )</h1>
<p>The abstract operation FromBase64 takes arguments <var>string</var> (a String), <var>alphabet</var> (<emu-val>"base64"</emu-val> or <emu-val>"base64url"</emu-val>), and <var>lastChunkHandling</var> (<emu-val>"loose"</emu-val>, <emu-val>"strict"</emu-val>, or <emu-val>"stop-before-partial"</emu-val>) and optional argument <var>maxLength</var> (a non-negative <emu-xref href="#integer" id="_ref_14068"><a href="notational-conventions.html#integer">integer</a></emu-xref>) and returns a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14069"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> with fields <var class="field">[[Read]]</var> (an <emu-xref href="#integer" id="_ref_14070"><a href="notational-conventions.html#integer">integer</a></emu-xref>), <var class="field">[[Bytes]]</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14071"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-data-blocks" id="_ref_14072"><a href="ecmascript-data-types-and-values.html#sec-data-blocks">byte values</a></emu-xref>), and <var class="field">[[Error]]</var> (a <emu-val>SyntaxError</emu-val> object or <emu-const>none</emu-const>). It performs the following steps when called:</p>
<emu-alg><ol><li>If <var>maxLength</var> is not present, then<ol><li>Set <var>maxLength</var> to 2<sup>53</sup> - 1.</li><li>NOTE: Because the input <emu-xref href="#sec-ecmascript-language-types-string-type" id="_ref_14073"><a href="ecmascript-data-types-and-values.html#sec-ecmascript-language-types-string-type">is a String</a></emu-xref>, the length of Strings is limited to 2<sup>53</sup> - 1 characters, and the output requires no more bytes than the input has characters, this limit can never be reached. However, it is editorially convenient to use a <emu-xref href="#finite" id="_ref_14074"><a href="ecmascript-data-types-and-values.html#finite">finite</a></emu-xref> value for <var>maxLength</var>.</li></ol></li><li>NOTE: The order of validation and decoding in the algorithm below is not observable. Implementations are encouraged to perform them in whatever order is most efficient, possibly interleaving validation with decoding.</li><li>If <var>maxLength</var> = 0, then<ol><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14075"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: 0, <var class="field">[[Bytes]]</var>: «&nbsp;», <var class="field">[[Error]]</var>: <emu-const>none</emu-const>&nbsp;}.</li></ol></li><li>Let <var>read</var> be 0.</li><li>Let <var>bytes</var> be a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14076"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>Let <var>chunk</var> be the empty String.</li><li>Let <var>chunkLength</var> be 0.</li><li>Let <var>index</var> be 0.</li><li>Let <var>length</var> be the length of <var>string</var>.</li><li>Repeat,<ol><li>Set <var>index</var> to <emu-xref aoid="SkipAsciiWhitespace" id="_ref_14077"><a href="indexed-collections.html#sec-skipasciiwhitespace">SkipAsciiWhitespace</a></emu-xref>(<var>string</var>, <var>index</var>).</li><li>If <var>index</var> = <var>length</var>, then<ol><li>If <var>chunkLength</var> &gt; 0, then<ol><li>If <var>lastChunkHandling</var> is <emu-val>"stop-before-partial"</emu-val>, then<ol><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14078"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <emu-const>none</emu-const>&nbsp;}.</li></ol></li><li>If <var>lastChunkHandling</var> is <emu-val>"strict"</emu-val>, then<ol><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14079"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li><emu-xref href="#assert" id="_ref_14080"><a href="notational-conventions.html#assert">Assert</a></emu-xref>: <var>lastChunkHandling</var> is <emu-val>"loose"</emu-val>.</li><li>If <var>chunkLength</var> = 1, then<ol><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14081"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>Set <var>bytes</var> to the <emu-xref href="#list-concatenation" id="_ref_14082"><a href="ecmascript-data-types-and-values.html#list-concatenation">list-concatenation</a></emu-xref> of <var>bytes</var> and !&nbsp;<emu-xref aoid="DecodeFinalBase64Chunk" id="_ref_14083"><a href="indexed-collections.html#sec-decodefinalbase64chunk">DecodeFinalBase64Chunk</a></emu-xref>(<var>chunk</var>, <emu-val>false</emu-val>).</li></ol></li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14084"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>length</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <emu-const>none</emu-const>&nbsp;}.</li></ol></li><li>Let <var>char</var> be the <emu-xref href="#substring" id="_ref_14085"><a href="ecmascript-data-types-and-values.html#substring">substring</a></emu-xref> of <var>string</var> from <var>index</var> to <var>index</var> + 1.</li><li>Set <var>index</var> to <var>index</var> + 1.</li><li>If <var>char</var> is <emu-val>"="</emu-val>, then<ol><li>If <var>chunkLength</var> &lt; 2, then<ol><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14086"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>Set <var>index</var> to <emu-xref aoid="SkipAsciiWhitespace" id="_ref_14087"><a href="indexed-collections.html#sec-skipasciiwhitespace">SkipAsciiWhitespace</a></emu-xref>(<var>string</var>, <var>index</var>).</li><li>If <var>chunkLength</var> = 2, then<ol><li>If <var>index</var> = <var>length</var>, then<ol><li>If <var>lastChunkHandling</var> is <emu-val>"stop-before-partial"</emu-val>, then<ol><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14088"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <emu-const>none</emu-const>&nbsp;}.</li></ol></li><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14089"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>Set <var>char</var> to the <emu-xref href="#substring" id="_ref_14090"><a href="ecmascript-data-types-and-values.html#substring">substring</a></emu-xref> of <var>string</var> from <var>index</var> to <var>index</var> + 1.</li><li>If <var>char</var> is <emu-val>"="</emu-val>, then<ol><li>Set <var>index</var> to <emu-xref aoid="SkipAsciiWhitespace" id="_ref_14091"><a href="indexed-collections.html#sec-skipasciiwhitespace">SkipAsciiWhitespace</a></emu-xref>(<var>string</var>, <var>index</var> + 1).</li></ol></li></ol></li><li>If <var>index</var> &lt; <var>length</var>, then<ol><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14092"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>If <var>lastChunkHandling</var> is <emu-val>"strict"</emu-val>, let <var>throwOnExtraBits</var> be <emu-val>true</emu-val>; else let <var>throwOnExtraBits</var> be <emu-val>false</emu-val>.</li><li>Let <var>decodeResult</var> be <emu-xref aoid="Completion" id="_ref_14093"><a href="notational-conventions.html#sec-completion-ao">Completion</a></emu-xref>(<emu-xref aoid="DecodeFinalBase64Chunk" id="_ref_14094"><a href="indexed-collections.html#sec-decodefinalbase64chunk">DecodeFinalBase64Chunk</a></emu-xref>(<var>chunk</var>, <var>throwOnExtraBits</var>)).</li><li>If <var>decodeResult</var> is an <emu-xref href="#sec-completion-record-specification-type" id="_ref_14095"><a href="ecmascript-data-types-and-values.html#sec-completion-record-specification-type">abrupt completion</a></emu-xref>, then<ol><li>Let <var>error</var> be <var>decodeResult</var>.<var class="field">[[Value]]</var>.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14096"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>Set <var>bytes</var> to the <emu-xref href="#list-concatenation" id="_ref_14097"><a href="ecmascript-data-types-and-values.html#list-concatenation">list-concatenation</a></emu-xref> of <var>bytes</var> and !&nbsp;<var>decodeResult</var>.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14098"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>length</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <emu-const>none</emu-const>&nbsp;}.</li></ol></li><li>If <var>alphabet</var> is <emu-val>"base64url"</emu-val>, then<ol><li>If <var>char</var> is either <emu-val>"+"</emu-val> or <emu-val>"/"</emu-val>, then<ol><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14099"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>Else if <var>char</var> is <emu-val>"-"</emu-val>, then<ol><li>Set <var>char</var> to <emu-val>"+"</emu-val>.</li></ol></li><li>Else if <var>char</var> is <emu-val>"_"</emu-val>, then<ol><li>Set <var>char</var> to <emu-val>"/"</emu-val>.</li></ol></li></ol></li><li>If the sole code unit of <var>char</var> is not an element of the <emu-xref href="#standard-base64-alphabet" id="_ref_14100"><a href="indexed-collections.html#standard-base64-alphabet">standard base64 alphabet</a></emu-xref>, then<ol><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14101"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>Let <var>remaining</var> be <var>maxLength</var> - the number of elements in <var>bytes</var>.</li><li>If <var>remaining</var> = 1 and <var>chunkLength</var> = 2, or if <var>remaining</var> = 2 and <var>chunkLength</var> = 3, then<ol><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14102"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <emu-const>none</emu-const>&nbsp;}.</li></ol></li><li>Set <var>chunk</var> to the <emu-xref href="#string-concatenation" id="_ref_14103"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>chunk</var> and <var>char</var>.</li><li>Set <var>chunkLength</var> to the length of <var>chunk</var>.</li><li>If <var>chunkLength</var> = 4, then<ol><li>Set <var>bytes</var> to the <emu-xref href="#list-concatenation" id="_ref_14104"><a href="ecmascript-data-types-and-values.html#list-concatenation">list-concatenation</a></emu-xref> of <var>bytes</var> and <emu-xref aoid="DecodeFullLengthBase64Chunk" id="_ref_14105"><a href="indexed-collections.html#sec-decodefulllengthbase64chunk">DecodeFullLengthBase64Chunk</a></emu-xref>(<var>chunk</var>).</li><li>Set <var>chunk</var> to the empty String.</li><li>Set <var>chunkLength</var> to 0.</li><li>Set <var>read</var> to <var>index</var>.</li><li>If the number of elements in <var>bytes</var> = <var>maxLength</var>, then<ol><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14106"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <emu-const>none</emu-const>&nbsp;}.</li></ol></li></ol></li></ol></li></ol></emu-alg>
</emu-clause>
<emu-clause id="sec-fromhex" type="abstract operation" aoid="FromHex">
<h1><span class="secnum">23.3.3.8</span> FromHex ( <var>string</var> [ , <var>maxLength</var> ] )</h1>
<p>The abstract operation FromHex takes argument <var>string</var> (a String) and optional argument <var>maxLength</var> (a non-negative <emu-xref href="#integer" id="_ref_14107"><a href="notational-conventions.html#integer">integer</a></emu-xref>) and returns a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14108"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> with fields <var class="field">[[Read]]</var> (an <emu-xref href="#integer" id="_ref_14109"><a href="notational-conventions.html#integer">integer</a></emu-xref>), <var class="field">[[Bytes]]</var> (a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14110"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#sec-data-blocks" id="_ref_14111"><a href="ecmascript-data-types-and-values.html#sec-data-blocks">byte values</a></emu-xref>), and <var class="field">[[Error]]</var> (a <emu-val>SyntaxError</emu-val> object or <emu-const>none</emu-const>). It performs the following steps when called:</p>
<emu-alg><ol><li>If <var>maxLength</var> is not present, set <var>maxLength</var> to 2<sup>53</sup> - 1.</li><li>Let <var>length</var> be the length of <var>string</var>.</li><li>Let <var>bytes</var> be a new empty <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14112"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref>.</li><li>Let <var>read</var> be 0.</li><li>If <var>length</var> <emu-xref aoid="modulo" id="_ref_14113"><a href="notational-conventions.html#eqn-modulo">modulo</a></emu-xref> 2 ≠ 0, then<ol><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14114"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>Repeat, while <var>read</var> &lt; <var>length</var> and the number of elements in <var>bytes</var> &lt; <var>maxLength</var>,<ol><li>Let <var>hexits</var> be the <emu-xref href="#substring" id="_ref_14115"><a href="ecmascript-data-types-and-values.html#substring">substring</a></emu-xref> of <var>string</var> from <var>read</var> to <var>read</var> + 2.</li><li>If <var>hexits</var> contains any code units which are not in <emu-val>"0123456789abcdefABCDEF"</emu-val>, then<ol><li>Let <var>error</var> be a newly created <emu-val>SyntaxError</emu-val> object.</li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14116"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <var>error</var>&nbsp;}.</li></ol></li><li>Set <var>read</var> to <var>read</var> + 2.</li><li>Let <var>byte</var> be the <emu-xref href="#integer" id="_ref_14117"><a href="notational-conventions.html#integer">integer</a></emu-xref> value represented by <var>hexits</var> in base-16 notation, using the letters <emu-val>A</emu-val> through <emu-val>F</emu-val> and <emu-val>a</emu-val> through <emu-val>f</emu-val> for digits with values 10 through 15.</li><li>Append <var>byte</var> to <var>bytes</var>.</li></ol></li><li>Return the <emu-xref href="#sec-list-and-record-specification-type" id="_ref_14118"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">Record</a></emu-xref> { <var class="field">[[Read]]</var>: <var>read</var>, <var class="field">[[Bytes]]</var>: <var>bytes</var>, <var class="field">[[Error]]</var>: <emu-const>none</emu-const>&nbsp;}.</li></ol></emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause></div></body></html>