You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>_predicate_ should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. `findLast` calls _predicate_ once for each element of the array, in descending index order, until it finds one where _predicate_ returns *true*. If such an element is found, `findLast` immediately returns that element value. Otherwise, `findLast` returns *undefined*.</p>
37391
+
<p>If a _thisArg_ parameter is provided, it will be used as the *this* value for each invocation of _predicate_. If it is not provided, *undefined* is used instead.</p>
37392
+
<p>_predicate_ is called with three arguments: the element, the index of the element in the array, and the object being traversed.</p>
37393
+
<p>`findLast` does not directly mutate the object on which it is called but the object may be mutated by the calls to _predicate_.</p>
37394
+
<p>The range of elements processed by `findLast` is set before the first call to _predicate_. Elements that are appended to the array after the call to `findLast` begins will not be visited by _predicate_. If existing elements of the array are changed, their value as passed to _predicate_ will be the value at the time that `findLast` visits them.</p>
37395
+
</emu-note>
37396
+
<p>When the `findLast` method is called, the following steps are taken:</p>
37397
+
<emu-alg>
37398
+
1. Let _O_ be ? ToObject(*this* value).
37399
+
1. Let _len_ be ? LengthOfArrayLike(_O_).
37400
+
1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception.
37401
+
1. Let _k_ be _len_ - 1.
37402
+
1. Repeat, while _k_ ≥ 0,
37403
+
1. Let _Pk_ be ! ToString(𝔽(_k_)).
37404
+
1. Let _kValue_ be ? Get(_O_, _Pk_).
37405
+
1. Let _testResult_ be ToBoolean(? Call(_predicate_, _thisArg_, « _kValue_, 𝔽(_k_), _O_ »)).
37406
+
1. If _testResult_ is *true*, return _kValue_.
37407
+
1. Set _k_ to _k_ - 1.
37408
+
1. Return *undefined*.
37409
+
</emu-alg>
37410
+
<emu-note>
37411
+
<p>The `findLast` function is intentionally generic; it does not require that its *this* value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
<p>_predicate_ should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. `findLastIndex` calls _predicate_ once for each element of the array, in descending index order, until it finds one where _predicate_ returns *true*. If such an element is found, `findLastIndex` immediately returns the index of that element value. Otherwise, `findLastIndex` returns -1.</p>
37419
+
<p>If a _thisArg_ parameter is provided, it will be used as the *this* value for each invocation of _predicate_. If it is not provided, *undefined* is used instead.</p>
37420
+
<p>_predicate_ is called with three arguments: the element, the index of the element in the array, and the object being traversed.</p>
37421
+
<p>`findLastIndex` does not directly mutate the object on which it is called but the object may be mutated by the calls to _predicate_.</p>
37422
+
<p>The range of elements processed by `findLastIndex` is set before the first call to _predicate_. Elements that are appended to the array after the call to `findLastIndex` begins will not be visited by _predicate_. If existing elements of the array are changed, their value as passed to _predicate_ will be the value at the time that `findLastIndex` visits them.</p>
37423
+
</emu-note>
37424
+
<p>When the `findLastIndex` method is called, the following steps are taken:</p>
37425
+
<emu-alg>
37426
+
1. Let _O_ be ? ToObject(*this* value).
37427
+
1. Let _len_ be ? LengthOfArrayLike(_O_).
37428
+
1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception.
37429
+
1. Let _k_ be _len_ - 1.
37430
+
1. Repeat, while _k_ ≥ 0,
37431
+
1. Let _Pk_ be ! ToString(𝔽(_k_)).
37432
+
1. Let _kValue_ be ? Get(_O_, _Pk_).
37433
+
1. Let _testResult_ be ToBoolean(? Call(_predicate_, _thisArg_, « _kValue_, 𝔽(_k_), _O_ »)).
37434
+
1. If _testResult_ is *true*, return 𝔽(_k_).
37435
+
1. Set _k_ to _k_ - 1.
37436
+
1. Return *-1*<sub>𝔽</sub>.
37437
+
</emu-alg>
37438
+
<emu-note>
37439
+
<p>The `findLastIndex` function is intentionally generic; it does not require that its *this* value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
37440
+
</emu-note>
37441
+
</emu-clause>
37442
+
37387
37443
<emu-clause id="sec-array.prototype.flat">
37388
37444
<h1>Array.prototype.flat ( [ _depth_ ] )</h1>
37389
37445
<p>When the `flat` method is called, the following steps are taken:</p>
<p>The interpretation and use of the arguments of %TypedArray%`.prototype.findLast` are the same as for `Array.prototype.findLast` as defined in <emu-xref href="#sec-array.prototype.findlast"></emu-xref>.</p>
38940
+
<p>When the `findLast` method is called, the following steps are taken:</p>
38941
+
<emu-alg>
38942
+
1. Let _O_ be the *this* value.
38943
+
1. Perform ? ValidateTypedArray(_O_).
38944
+
1. Let _len_ be _O_.[[ArrayLength]].
38945
+
1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception.
38946
+
1. Let _k_ be _len_ - 1.
38947
+
1. Repeat, while _k_ ≥ 0,
38948
+
1. Let _Pk_ be ! ToString(𝔽(_k_)).
38949
+
1. Let _kValue_ be ! Get(_O_, _Pk_).
38950
+
1. Let _testResult_ be ToBoolean(? Call(_predicate_, _thisArg_, « _kValue_, 𝔽(_k_), _O_ »)).
38951
+
1. If _testResult_ is *true*, return _kValue_.
38952
+
1. Set _k_ to _k_ - 1.
38953
+
1. Return *undefined*.
38954
+
</emu-alg>
38955
+
<p>This function is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.</p>
<p>The interpretation and use of the arguments of %TypedArray%`.prototype.findLastIndex` are the same as for `Array.prototype.findLastIndex` as defined in <emu-xref href="#sec-array.prototype.findlastindex"></emu-xref>.</p>
38961
+
<p>When the `findLastIndex` method is called, the following steps are taken:</p>
38962
+
<emu-alg>
38963
+
1. Let _O_ be the *this* value.
38964
+
1. Perform ? ValidateTypedArray(_O_).
38965
+
1. Let _len_ be _O_.[[ArrayLength]].
38966
+
1. If IsCallable(_predicate_) is *false*, throw a *TypeError* exception.
38967
+
1. Let _k_ be _len_ - 1.
38968
+
1. Repeat, while _k_ ≥ 0,
38969
+
1. Let _Pk_ be ! ToString(𝔽(_k_)).
38970
+
1. Let _kValue_ be ! Get(_O_, _Pk_).
38971
+
1. Let _testResult_ be ToBoolean(? Call(_predicate_, _thisArg_, « _kValue_, 𝔽(_k_), _O_ »)).
38972
+
1. If _testResult_ is *true*, return 𝔽(_k_).
38973
+
1. Set _k_ to _k_ - 1.
38974
+
1. Return *-1*<sub>𝔽</sub>.
38975
+
</emu-alg>
38976
+
<p>This function is not generic. The *this* value must be an object with a [[TypedArrayName]] internal slot.</p>
<p>The interpretation and use of the arguments of %TypedArray%`.prototype.forEach` are the same as for `Array.prototype.forEach` as defined in <emu-xref href="#sec-array.prototype.foreach"></emu-xref>.</p>
0 commit comments