3

In this block of code, I'm finding the "SCRIPT1010: Expected Identifier" Error on the first line in IE11. This works perfectly in all other major browsers.

for (let [key, value] of Object.entries(CompanySettings)) {
 if (value == true) {    
   document.getElementById(key).removeAttribute("checked");
 }
 if (value == false) {
  document.getElementById(key).setAttribute("checked", "no");
 }
}

I'm assuming this is because it's an ES6 feature that's not available in IE, but I'm wondering if there's an plain old JS alternative I could use to the let.. of.. that works in IE11. I'm not really interested in adding an extra library just to get this block running.

3
  • es6 synatx is not supporting in IE Commented Feb 13, 2020 at 8:07
  • teamtreehouse.com/community/… Commented Feb 13, 2020 at 8:07
  • Use Babel and polyfills Commented Feb 13, 2020 at 8:08

1 Answer 1

2

You could take a for ... in statement and iterate the keys.

for (var key in CompanySettings) {
    if (CompanySettings[key]) { // assuming true or false values
        document.getElementById(key).removeAttribute("checked");
    } else {
        document.getElementById(key).setAttribute("checked", "no");
    }
}

Maybe you need another check for not own properties

for (var key in CompanySettings) {
    if (!CompanySettings.hasOwnProperty(key)) continue;
    if (CompanySettings[key]) { // assuming true or false values
        document.getElementById(key).removeAttribute("checked");
    } else {
        document.getElementById(key).setAttribute("checked", "no");
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.