JavaScript: Array.prototype.findIndex
New in JS2015.
findIndex
return the index of the element.find
return the element.
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