解决ie11以下不兼容array数组的findIndex方法
2020-02-04 07:49
330 查看
解决ie11以下不兼容array数组的findIndex方法
最近在做项目的兼容问题,总是碰到令人头疼的各种不支持问题。真的是。。。
下面说一下关于ie11以下不兼容array数组的findIndex方法的解决方案
// 兼容ie数组没有findIndex方法 if (!Array.prototype.findIndex) { Object.defineProperty(Array.prototype, 'findIndex', { value: function(predicate:any) { // 1. Let O be ? ToObject(this value). if (this == null) { throw new TypeError('"this" is null or not defined'); } var o = Object(this); // 2. Let len be ? ToLength(? Get(O, "length")). var len = o.length >>> 0; // 3. If IsCallable(predicate) is false, throw a TypeError exception. if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } // 4. If thisArg was supplied, let T be thisArg; else let T be undefined. var thisArg = arguments[1]; // 5. Let k be 0. var k = 0; // 6. Repeat, while k < len while (k < len) { // a. Let Pk be ! ToString(k). // b. Let kValue be ? Get(O, Pk). // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). // d. If testResult is true, return k. var kValue = o[k]; if (predicate.call(thisArg, kValue, k, o)) { return k; } // e. Increase k by 1. k++; } // 7. Return -1. return -1; } }); }
- 点赞 2
- 收藏
- 分享
- 文章举报
相关文章推荐
- 关于Java中使用split()方法时报ArrayIndexOutOfBoundsException数组越界异常解决方法
- 解决IE11 Array没有find的方法
- 以下反向遍历array数组的方法有什么错误?
- TextView 显示内容时出现 ArrayIndexOutOfBoundsException 的解决方法(Android 4.1)
- 数组实例的find() 和 findIndex()方法
- Tomcat 或JBOSS java.lang.ArrayIndexOutOfBoundsException: 8192原因及其解决方法
- TextView 显示内容时出现 ArrayIndexOutOfBoundsException 的解决方法(Android 4.1)
- java.lang.ArrayIndexOutOfBoundsException(数组越界)处理方法
- 解决ie9以下不兼容getElementsByClassName的方法
- 关于vue项目启动报错Error:Cannot find module 'array-includes'解决方法
- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at SimpleCalculator.main的解决方法
- CP2K运行时显示Index to radix array not found 错误的解决方法
- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at SimpleCalculator.main的解决方法
- 解决IE8及以下CSS3选择器nth-child() 不兼容问题的解决方法
- ES6中Array.find()方法和Array.findIndex()方法
- Vue中常用的数组方法.filter()、.map()、.forEach()、.find()、.findIndex()、.some()、.every()
- web前端,兼容IE6有以下BUG的解决方法
- sharepoint 2013 office web app 2013 文档在线浏览 IE11 浏览器不兼容解决方法
- sharepoint 2013 office web app 2013 文档在线浏览 IE11 浏览器不兼容解决方法
- 完美解决ie8以下不兼容h5的方法