-1

Need an alternative for Object.Entries in Internet Explorer. I am not looking for polyfills as part of the solution. Below is a code snippet depicting the issue -

for (const [Key, Value] of Object.entries(Name)) {

}

In IE the above "for loop" wont work but it works in other browsers. I need to extract key and value from the object "Name"

3
  • 1
    You also can't use destructuring in IE.
    – Barmar
    Commented Dec 17, 2020 at 17:46
  • 1
    Then just use a plain old for...in... loop. Or in other words: What's the problem?
    – Andreas
    Commented Dec 17, 2020 at 17:50
  • 1
    Can you please inform us of the error message that you are getting on your side? If we see the documentation then we can notice that it is not supported in the IE browser. But the polyfill is available to fix the issue. Can you please inform us why you don't want to use the polyfill? It can be an easy fix for the issue. It can help us to understand the issue in a better way. Commented Dec 18, 2020 at 3:40

1 Answer 1

0

Just loop over the object itself, that will return the keys, then you can get the value with indexing.

for (var Key in Name) {
    if (Name.hasOwnProperty(Key)) {
        var Value = Name[Key];
        // code here
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.