详细问题描述
[内容]
for in 遍历数组 如果 数组重写 Array.prototype.findIndex 会多遍历一次
重现步骤
[步骤]
if (!Array.prototype.findIndex) {
Array.prototype.findIndex = function(predicate) {
if (this === null) {
throw new TypeError('Array.prototype.findIndex called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return i;
}
}
return -1;
};
}
var myArray = new Array(1,2,3,4,5);
for(var i in myArray)
{
console.log(i);
}
[结果]
0 1 2 3 4 findIndex
[期望]
0 1 2 3 4
运行环境
[系统版本]
[浏览器版本]
[IDE版本]
[mui版本]
附件
[代码片段]
[安装包]
联系方式
[QQ] 136177789
[电话] 13810880391