企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
![](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)); ~~~