| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex | [Back] [Original] |
Get to know MDN better
const array = [5, 12, 50, 130, 44];
const isLargeNumber = (element) => element > 45;
console.log(array.findLastIndex(isLargeNumber));
// : 3
// Index of element with value: 130
findLastIndex(callbackFn)
findLastIndex(callbackFn, thisArg)
-1
findLastIndex() callbackFn callbackFn findLastIndex() callbackFn findLastIndex() -1
-1
function isPrime(n) {
if (n < 2) {
return false;
}
if (n % 2 === 0) {
return n === 2;
}
for (let factor = 3; factor * factor <= n; factor += 2) {
if (n % factor === 0) {
return false;
}
}
return true;
}
console.log([4, 6, 8, 12].findLastIndex(isPrime)); // -1, not found
console.log([4, 5, 7, 8, 9, 11, 12].findLastIndex(isPrime)); // 5
array filter() findLastIndex()
const numbers = [3, -1, 1, 4, 1, 5, 9, 2, 6];
const lastTrough = numbers
.filter((num) => num > 0)
.findLastIndex((num, idx, arr) => {
// arr
//
if (idx > 0 && num >= arr[idx - 1]) return false;
if (idx < arr.length - 1 && num >= arr[idx + 1]) return false;
return true;
});
console.log(lastTrough); // 6
undefined
console.log([1, , 3].findLastIndex((x) => x === undefined)); // 1
findLastIndex() this length length
const arrayLike = {
length: 3,
0: 2,
1: 7.3,
2: 4,
3: 3, // length 3 findLastIndex()
};
console.log(
Array.prototype.findLastIndex.call(arrayLike, (x) => Number.isInteger(x)),
); // 2
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.findlastindex |
Arrayat()concat()copyWithin()entries()every()fill()filter()find()findIndex()findLast()findLastIndex()flat()flatMap()forEach()includes()indexOf()join()keys()lastIndexOf()map()pop()push()reduce()reduceRight()reverse()shift()slice()some()sort()splice()toLocaleString()toReversed()toSorted()toSpliced()toString()unshift()values()with()[Symbol.iterator]()Object/Function| Web Proxy Viewer | New URL | Original Page |