多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
![](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)); ~~~