[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/findLast [Back]  [Original]

TypedArray.prototype.findLast() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

TypedArray.prototype.findLast()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2022 8.

TypedArray findLast() . undefined . Array.prototype.findLast() .

In this article

function isNegative(element /*, index, array */) {
  return element < 0;
}

const int8 = new Int8Array([10, 0, -10, 20, -30, 40, 50]);

console.log(int8.find(isNegative));
// Expected output: -30

js
findLast(callbackFn)
findLast(callbackFn, thisArg)

callbackFn

. , . .

element

.

index

.

array

findLast() .

thisArg Optional

callbackFn this . .

( ) . undefined .

Array.prototype.findLast() . .

, undefined .

js
function isPrime(element) {
  if (element % 2 === 0 || element < 2) {
    return false;
  }
  for (let factor = 3; factor <= Math.sqrt(element); factor += 2) {
    if (element % factor === 0) {
      return false;
    }
  }
  return true;
}

let uint8 = new Uint8Array([4, 6, 8, 12]);
console.log(uint8.findLast(isPrime)); // undefined (   )
uint8 = new Uint8Array([4, 5, 7, 8, 9, 11, 12]);
console.log(uint8.findLast(isPrime)); // 11

.

js
//  2,3,4    
//   0  .
const uint8 = new Uint8Array([0, 1, , , , 5, 6]);

//   .
//      .
uint8.findLast((value, index) => {
  console.log(`Visited index ${index} with value ${value}`);
});

//      
uint8.findLast((value, index) => {
  //    3 
  if (index === 6) {
    console.log("Set uint8[3] to 44");
    uint8[3] = 44;
  }
  //  3     
  console.log(`Visited index ${index} with value ${value}`);
});
// Visited index 6 with value 6
// Visited index 5 with value 5
// Visited index 4 with value 0
// Visited index 3 with value 0
// Visited index 2 with value 0
// Visited index 1 with value 1
// Visited index 0 with value 0
// Set uint8[3] to 44
// Visited index 6 with value 6
// Visited index 5 with value 5
// Visited index 4 with value 0
// Visited index 3 with value 44
// Visited index 2 with value 0
// Visited index 1 with value 1
// Visited index 0 with value 0

Specification
ECMAScript 2027 LanguageSpecification
# sec-%typedarray%.prototype.findlast


Web Proxy Viewer  |  New URL  |  Original Page