0 points

findLastIndex


dashboard

Fri Oct 23 2020 16:29:07 GMT+0000 (UTC)

Posted by @rawilk #javascript

const findLastIndex = (array, predicate) => {
    let l = array.length;
    while (l--) {
        if (predicate(array[l], l, array)) {
            return l;
        }
    }

    return -1;
};
content_copy Copy

Find the last index of something in an array where a predicate (callback) is true. Based off a stack overflow answer.

https://stackoverflow.com/a/53187807