SOURCE

Array.prototype.findIndex = (array, predicate, reverse = false) => {
    const { length } = array;
    let idx = reverse ? length : -1;
    while (reverse ? idx-- : ++idx < length) {
        if (predicate(array[idx], idx, array)) {
            return idx;
        }
    }
    return -1;
}

let array = [{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': true }]

console.log(array.findIndex(array, function(item, index, array){
    console.log(item)
    return item.user == 'pebbles'
}, false))
console 命令行工具 X clear

                    
>
console