JS: Array.prototype.findIndex

By Xah Lee. Date: . Last updated: .

New in JS2015.

See Array.prototype.find

const isEven = (x => ( x % 2 === 0 ? true : false ) )

console.log( [7,3,4,2].findIndex (isEven) ); // 2

// if not found, return undefined
console.log( [1,3,5].find (isEven) ); // undefined

JavaScript, Array Search

BUY ΣJS JavaScript in Depth