Array.from fails with Set on IE11
See original GitHub issueOn IE11 (on Windows 10, if that’s important), when Array.from is passed a set, the Array.from polyfill is failing to detect the set. This appears to be an issue with the order in which polyfills are being loaded:
- Array.from first captures the Set.size property descriptor using Object.getOwnPropertyDescriptor(Set.prototype, ‘size’).get
- Then the Set polyfill kicks in and defines a new Set.size prototype using Object.defineProperty(Set.prototype, ‘size’, {
Placing a breakpoint in the Array.from polyfill’s isSet
function, you can see that:
- executing
setSize.call(set)
throws an exception - executing
Object.getOwnPropertyDescriptor(Set.prototype, 'size').get.call(set)
succeeds Object.getOwnPropertyDescriptor(Set.prototype, 'size').get === setSize
is false
In other words, using an uncaptured value for the Set.prototype.size.get
function succeeds, but using the previously captured value fails. So it looks like Array.from
is capturing IE11’s native Set.size.get
function, but then later trying to invoke the polyfilled version and throwing an exception as a result.
Here’s what the service is loading
UA detected: ie/11.0.0
Features requested: Array.prototype.@@iterator,Array.prototype.find,Array.prototype.includes,IntersectionObserver,Promise,Symbol,WeakMap,default,fetch,matchMedia,navigator.sendBeacon
Earlier resolutions
``` Object.assign, License: CC0 (required by "default", "_Iterator", "_ArrayIterator", "Array.prototype.@@iterator", "Array.from") Symbol, License: MIT (required by "Map", "default", "Set", "Symbol.iterator", "Array.prototype.@@iterator", "Symbol.species", "_Iterator", "_ArrayIterator", "Array.from", "Symbol.toStringTag") Symbol.iterator, License: MIT (required by "Array.prototype.@@iterator", "Map", "default", "Set", "_Iterator", "_ArrayIterator", "Array.from") Symbol.toStringTag, License: MIT (required by "_Iterator", "_ArrayIterator", "Array.prototype.@@iterator", "Array.from", "default") _Iterator, License: MIT (required by "_ArrayIterator", "Array.prototype.@@iterator", "Array.from", "default") Object.setPrototypeOf, License: MIT (required by "_ArrayIterator", "Array.prototype.@@iterator", "Array.from", "default") String.prototype.includes, License: CC0 (required by "default", "String.prototype.contains", "_ArrayIterator", "Array.prototype.@@iterator", "Array.from") String.prototype.contains, License: CC0 (required by "_ArrayIterator", "Array.prototype.@@iterator", "Array.from", "default") _ArrayIterator, License: MIT (required by "Array.prototype.@@iterator", "Array.from", "default") Array.prototype.@@iterator, License: CC0 Array.prototype.find, License: CC0 Array.prototype.includes, License: CC0 Event, License: CC0 (required by "default", "IntersectionObserver", "CustomEvent", "XMLHttpRequest", "fetch", "navigator.sendBeacon") IntersectionObserver, License: CC0 Promise, License: MIT (required by "default", "fetch") WeakMap, License: https://github.com/webcomponents/webcomponentsjs/blob/master/LICENSE.md fetch, License: MIT navigator.sendBeacon, License: MIT Number.isFinite, License: MIT (required by "Array.from", "default") ```Number.isNaN, License: MIT (required by "default", "Array.from", "Map", "Set")
Array.from, License: CC0 (required by "default")
Array.of, License: MIT (required by "default")
followed by
``` Array.prototype.fill, License: CC0 (required by "default") CustomEvent, License: CC0 (required by "default") _DOMTokenList, License: CC0 (required by "DOMTokenList", "default") DOMTokenList, License: CC0 (required by "default") _mutation, License: CC0 (required by "DocumentFragment.prototype.append", "default", "DocumentFragment.prototype.prepend", "Element.prototype.after", "Element.prototype.append", "Element.prototype.before", "Element.prototype.prepend", "Element.prototype.remove", "Element.prototype.replaceWith") DocumentFragment.prototype.append, License: CC0 (required by "default") DocumentFragment.prototype.prepend, License: CC0 (required by "default") Element.prototype.after, License: CC0 (required by "default") Element.prototype.append, License: CC0 (required by "default") Element.prototype.before, License: CC0 (required by "default") Element.prototype.matches, License: CC0 (required by "default", "Element.prototype.closest") Element.prototype.closest, License: CC0 (required by "default") Element.prototype.prepend, License: CC0 (required by "default") Element.prototype.remove, License: CC0 (required by "default") Element.prototype.replaceWith, License: CC0 (required by "default") Symbol.species, License: MIT (required by "Map", "default", "Set") Map, License: CC0 (required by "default") Node.prototype.contains, License: CC0 (required by "default") ```Set, License: CC0 (required by "default")
String.prototype.endsWith, License: CC0 (required by "default")
String.prototype.startsWith, License: CC0 (required by "default")
URL, License: CC0 (required by "default")
Issue Analytics
- State:
- Created 6 years ago
- Comments:12
Top Results From Across the Web
Alternative or polyfill for Array.from on the Internet Explorer
I am getting error after adding your code and checked in Internet Explorer 11. This site overrides Array.from() with an implementation that doesn't...
Read more >Array.isArray() - JavaScript - MDN Web Docs
The Array.isArray() static method determines whether the passed value is an Array.
Read more >JavaScript Array from() Method - W3Schools
from() is a static property of the JavaScript Array object. You can only use it as Array.from(). Using x.from(), where x is an...
Read more >IE11 - DOM elements saved in arrays have no innerHTML ...
The issue is that IE11 is not saving the innerHTML of the options when it first builds the array. Look at the cascades...
Read more >Debug JavaScript in Internet Explorer 11 in 7 easy steps
Executing the expression in the Console shows it returns an empty array — this is where the error comes from! Since it returns...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just come accross this issue when trying to create an array of unique items like so:
const toUniqueArray = array => [...new Set(array)];
A simple fix that works in IE11 and doesn’t cause problems in other browsers is to replace the above with:
const toUniqueArray = array => [...new Set(array).values()];
I’d guess (but haven’t tested) that this would work with
Array.from
as well.Hi all, this looks to have been fixed in a recent release. Here is a screenshot of it working in IE11 using the code
Array.from(new Set([1,2,3]))
.