I am working with the FormData
object, while my code works well on Chrome, Microsoft Edge spits out the following error message Object doesn't support property or method 'entries'
– which corresponds to the following code:
for(let pair of formData.entries()) {
...
}
I've tried replacing .entries()
with .getAll()
, however Microsoft Edge doesn't recognize either of both methods.
Is there a way to get this functionality (iterating over FormData
files) out of Microsoft Edge?
FormData Microsoft Edge Console Dump
Essentially, a polyfill is a way you can manually define a function that isn't natively supported on a specific platform/browser.
In your case, there is a basic definition of the function
Object.entries
given here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#PolyfillThey provide this simple, ready to deploy definition:
Looking at the code above, the first thing it checks is if
Object.entries
exists. If it does, no worries, but if it doesn't exist, then it creates it... As long as this function gets defined before you actually call it in your code, you should be fine.Using something like angular-cli, they provide a polyfills.ts file (which gets executed before your app is run) where you can place code like this or import files containing definitions you'll need.
10/30/2018 UPDATE:
@apsillers correctly pointed out the answer above does not apply to
FormData.entries()
, but toObject.entries()
instead.Solution for
FormData.entries()
(this worked for me): https://stackoverflow.com/a/49556416/3806701Basically, import this poly-fill:
Then you can iterate
FormData
as follows:If you're in an Angular App please add this line to your polyfills.ts file
It will import all the new methods on Object, including entries