Reputation: 45
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.
Upvotes: 3
Views: 895
Reputation: 386654
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");
}
}
Upvotes: 2