JavaScript配列findIndex
find

findIndex配列

flat

条件を満たす最初の要素のインデックスを返します。

構文

arr.findIndex(callbackFn)

使用例

下記の値を入力するとサンプルに即時反映されます。

const
numbers
idx
findIndex
console
const numbers = [10, 20, 30, 40];
const idx = numbers.findIndex((n) => n > 25);
console.log(idx);   // 2