最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Array.prototype.find() vs IE11 - Stack Overflow

programmeradmin1浏览0评论

states The find() method is not supported by IE11.

At the same time I'm testing this find() method in IE11 and I didn't find any traces of any wrong behavior.

I've also tested in IE11 the code

function isPrime(element, index, array) {
  var start = 2;
  while (start <= Math.sqrt(element)) {
    if (element % start++ < 1) return false;
  }
  return (element > 1);
}

console.log([4, 5, 8, 12].find(isPrime)); // 5

https://caniuse./#search=find states The find() method is not supported by IE11.

At the same time I'm testing this find() method in IE11 and I didn't find any traces of any wrong behavior.

I've also tested in IE11 the code

function isPrime(element, index, array) {
  var start = 2;
  while (start <= Math.sqrt(element)) {
    if (element % start++ < 1) return false;
  }
  return (element > 1);
}

console.log([4, 5, 8, 12].find(isPrime)); // 5

from SO: Array.prototype.find() is undefined

Yes, in IE11 it returns the expected result of 5 instead of TypeError: undefined is not a function, as SO: Array.prototype.find() is undefined in 2014 stated.

So... Am I missing something and IE11 really doesn't work properly with Array.prototype.find , or the last updates of IE11 that were made a while ago (but later than the SO question above was discussed in 2014) became to support this method?

Is https://caniuse./#search=find correct when says IE11 doesn't support Array.prototype.find ? Any evidence?

Thank you.

UPD: here is the screen of my IE11:

Share Improve this question edited Mar 13, 2019 at 9:47 Haradzieniec asked Mar 13, 2019 at 9:34 HaradzieniecHaradzieniec 9,34833 gold badges122 silver badges227 bronze badges 2
  • 1 You're running this in the context of SO? Well, SO may have defined that method using a polyfill… Try this again on an "empty" page! – deceze Commented Mar 13, 2019 at 9:49
  • 1 No, it's from another website. The SO background is just another (but not third) window. That might be a reason to find if it that method was defined on the website where I do tests. I will let you know. And yes - I see in the Run code snippet in the SO it causes an error in IE11. – Haradzieniec Commented Mar 13, 2019 at 9:52
Add a ment  | 

2 Answers 2

Reset to default 6

Everything you have read is correct. There is something flawed about your tests. Perhaps you included a Polyfill that added the method in IE11.

You can try following steps to validate:

  1. Open a blank tab in IE.
  2. Open console in dev tools.
  3. Enter following code: [1,2,3].find(function(n) { !!n; })
    • If above code throws error (which it should), you are using a polyfill. Hence your code does not break.
    • If it works, only explanation is that somehow, some update has added its definition. But this is very unlikely as MS has stopped support for it.

This is what I get:

发布评论

评论列表(0)

  1. 暂无评论