JS: Array.prototype.findIndex
(new in JS: ECMAScript 2015)
similar to JS: Array.prototype.find but return the index of the element found.
if not found, return -1.
const isEven = (x) => (x % 2 === 0 ? true : false); console.log([7, 3, 4, 2].findIndex(isEven) === 2); // if not found, return -1 console.log([1, 3, 5].findIndex(isEven) === -1);