因此,我編寫了(由于缺乏答案+提高我的技能)一個搜索腳本,該腳本基本上可以完成.indexOf所做的操作。function search(ref, data) { var x var y var result = [] if (data == '' || data == null) { } else { for (x = 0; x < data.length; x++) { if (data[x] == ref[0]) { //achando match inicial var proto = []; for (y = 0; y < ref.length; y++) { if (data[x+y] == ref[y]) { //gravando tentativas de match completo proto.push(data[x+y]) } } var proto2 = proto.join('') if (proto2 == ref) { //testando match completo result.push(x) } } } } if (result == '' || result == null) { } else { return result[0] }}它在其他不需要太多循環的小代碼和自定義函數中工作正常,但是當我編寫一個更強大的腳本時,我發現我的代碼比本機.indeOf慢大約3000倍。為什么我會產生這樣的差額?
性能慢的自定義腳本 GAS
慕森王
2022-09-02 17:14:18