前端知识学习

String.prototype.myIndexOf = function(str){
    var sourceArr = this.split('');
    var num = -1;
    for(var i in sourceArr){
        if(sourceArr[i]===str.slice(0,1)){
            if(str===this.slice(i,Number(i)+str.length)){
                num = i
            }
        }
    }
    return num
}
var a = 'abdddcdefghi'
var b = a.myIndexOf('de')
console.log(b)