简体   繁体   中英

javascript findIndex issue with IE

I've just completed a small form and found out that how I'm using findIndex doesn't work with IE.

Here is an example of the issue.

var people = [
  {name:"Mike", age:"25"},
  {name:"Bill", age:"35"},
  {name:"Terry", age:"44"}
];
console.log(people.findIndex(x => x.name=="Bill" ));

What would be the fastest way to fix this issue for IE?

find index support for browsers

    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

So you need to modify your code something similar to below to work in all browsers.

var index;
for(var i=0;i<people.length;i++){
  if(people[i].name == 'billi'){
   index = i
 }
}

More info

这对IE来说是最好的

people.findIndex(function(x){ x.name=="Bill" }));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM