As others have noted, itβs easy enough to collapse your own, which you can save in your specific use case:
// Find the index of the first element in array // meeting specified condition. // var findIndex = function(arr, cond) { var i, x; for (i in arr) { x = arr[i]; if (cond(x)) return parseInt(i); } }; var moreThanTwo = function(x) { return x > 2 } var i = findIndex([1, 2, 3, 4], moreThanTwo)
Or if you are a CoffeeScripter:
findIndex = (arr, cond) -> for i, x of arr return parseInt(i) if cond(x)
joyrexus Jul 05 '14 at 16:06 2014-07-05 16:06
source share