| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 9.
Array findIndex() .
-1 .
find() .
const array1 = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element > 13;
console.log(array1.findIndex(isLargeNumber));
// Expected output: 3
findIndex(callbackFn)
findIndex(callbackFn, thisArg)
. -1 .
findIndex() . callbackFn , callbackFn . findIndex() . callbackFn findIndex() -1 . .
. -1 .
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;
}
console.log([4, 6, 8, 9, 12].findIndex(isPrime)); // -1,
console.log([4, 6, 7, 9, 12].findIndex(isPrime)); // 2 (array[2] is 7)
array , . filter() findIndex() .
const numbers = [3, -1, 1, 4, 1, 5, 9, 2, 6];
const firstTrough = numbers
.filter((num) => num > 0)
.findIndex((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(firstTrough); // 1
undefined .
console.log([1, , 3].findIndex((x) => x === undefined)); // 1
findIndex() this length length .
const arrayLike = {
length: 3,
"-1": 0.1, // -1 < 0 findIndex() .
0: 2,
1: 7.3,
2: 4,
};
console.log(
Array.prototype.findIndex.call(arrayLike, (x) => !Number.isInteger(x)),
); // 1
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.findindex |
core-js Array.prototype.findIndex ArrayArray.prototype.find()Array.prototype.findLast()Array.prototype.findLastIndex()Array.prototype.indexOf()Array.prototype.lastIndexOf()TypedArray.prototype.findIndex()This page was last modified on 2025 10 10 by MDN contributors.
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/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |