indexOf & lastIndexOf

Array.prototype.myIndexOf = function(ele,start = 0){
    for(let i = start;i < this.length;i++){
        let item = this[i]
        if(ele === item){
            return i
        }
    }
    return -1
}
Array.prototype.myLastIndexOf = function(ele,start = this.length - 1){
    for(let i = start;i > -1;i--){
        let item = this[i]
        if(ele === item){
            return i
        }
    }
    return -1
}
以自己现在的努力程度,还没有资格和别人拼天赋
原文地址:https://www.cnblogs.com/zhenjianyu/p/13695518.html