javascript findIndex 与 IE 的问题

标签 javascript internet-explorer

我刚刚完成了一个小表单,发现我使用 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
 }
}

More info

关于javascript findIndex 与 IE 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39456640/

相关文章:

javascript - 即使我调用了 bind(),ReactJS 状态也未定义

javascript - 如何在 IE11 中克隆 jQuery 对象及其子对象而不使用引用

angularjs - 在 AngularJS 中设置 window.location 或 window.open 在 IE 11 中给出 "access is denied"

html - 在 Edge 和 IE 上打印时 HTML 上的不同元素顺序

javascript - 无法在带有 webpack/rollup/react 的外部库中使用 Material UI

Javascript——带有简单加法器函数的闭包

javascript - 计算值的总和

javascript - jQuery 自动完成菜单单击图像将数据发布到 Express 服务器

html - 我如何强制 IE *不* 使用兼容模式?

javascript - Internet Explorer 现代化工具