1 var arr = [1,2,3]; 2 3 Array.prototype.indexOf = Array.prototype.indexOf || function(obj){ 4 for(var i = 0, len = this.length; i < len; i++){ 5 if(this[i] == obj){ 6 console.log("xx") 7 return i; 8 } 9 } 10 }; 11 12 console.log(arr.indexOf(3)) 13 14 15 16 //var str = "kengdie"; 17 //alert(str.indexOf("e"));// 测试 String.prototype.indexOf 没有兼容问题