I'm trying to iterate over an array of HTMLCollections (tbody element with checkboxes inside) in JavaScript for a Chrome Extension. The length of this HTMLCollection will vary from user to user as well as each element's innerHTML.
I'd like to do something like:
for(let i = 0; i < HTMLCollection.length; i++){
    let identifier = 'NO' + i;
    chrome.storage.sync.get([identifier], result => {
        console.log(result.identifier) //Returns undefined
    });
    // Create checkbox element
    let checkbox = document.createElement("input");
    DOMIdentifyer.appendChild(checkbox);
    // Waits for a change in each checkbox
    checkbox.addEventListener('change', e => {
        if(e.target.checked) {
            chrome.storage.sync.set({identifier: 'true'}, () => {
                console.log(identifier + ': Value is set to true');
            });
        }
        else {
            chrome.storage.sync.set({identifier: 'false'}, () => {
                console.log(course_identifier + ': Value is set to false');
            });
        }
    });
}
The above code executes fine client-side but it does not restore the value on reload. This works fine if I do it with static strings like chrome.storage.sync.set({'foo': 'bar'});.
So my question is: How do I do this? Is it even possible to manage the Chrome.storage API dynamically?
