合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
![](https://img.kancloud.cn/48/2c/482c6362fb45965e8fe977d8a95a1b7f_1138x102.png) ~~~ ~ function () { // function myIndexOf(T) { // let lenT = T.length, // lenS = this.length, // res=-1; // if(lenT > lenS) return -1; // for (let i = 0; i < lenS - lenT; i++) { // let char = this[i]; // if(this.substr(i,lenT) === T){ // res = i; // break; // } // } // return res; // } function myIndexOf(T) { let reg = new RegExp(T), res = reg.exec(this); return res ===null ? -1 : res.index; } String.prototype.myIndexOf= myIndexOf; }(); let S = "zhufengpeixun"; T = "pei"; console.log(S.myIndexOf(T)); ~~~