我刚刚完成了一个小表单,发现我使用 findIndex 的方式不适用于 IE。
这是问题的示例。
var people = [
{name:"Mike", age:"25"},
{name:"Bill", age:"35"},
{name:"Terry", age:"44"}
];
console.log(people.findIndex(x => x.name=="Bill" ));
解决 IE 问题的最快方法是什么?
最佳答案
查找浏览器的索引支持
Chrome 45.0 and above: Supports
Firefox 25.0 and above: Supports
Internet Explorer: No support
Microsoft Edge: Supports
Opera: Supports
Safari 7.1 and above: Supports
因此,您需要修改类似于下面的代码才能在所有浏览器中工作。
var index;
for(var i=0;i<people.length;i++){
if(people[i].name == 'billi'){
index = i
}
}
关于javascript findIndex 与 IE 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39456640/