I can't seem to find out why this does not work from reading the Chrome API Reference so I was wondering if anyone here could tell me why If I save like this:
// grab element and save to storage API
let ELEMENT_DATA = [some string];
chrome.storage.sync.set({"ELEMENT_NAME": ELEMENT_DATA }); //this is the important bit because of the "" around ELEMENT_NAME.
and get like this:
chrome.storage.sync.get(["ELEMENT_NAME"], function (result) {
console.log(result.ELEMENT_NAME.id);
});
There is no problem. Although I need to set and get with a variable name that holds a string like this.
for(let i = 0; i < count; i++){
let ELEMENT_NAME = "ELEMENT" + i; /// = ELEMENT0 and so on...
let ELEMENT_DATA = [some string];
chrome.storage.sync.set({ELEMENT_NAME: ELEMENT_DATA }); //PASSING ELEMENT_NAME and not a direct string "" is the issue
}
So I thought i could solve this if I JSON.stringify the ELEMENT_NAME variable like this:
for(let i = 0; i < count; i++){
let ELEMENT_NAME = "ELEMENT" + i; /// = ELEMENT0 and so on...
let ELEMENT_DATA = [some string];
let ELEMENT_NAME_STR = JSON.stringify(ELEMENT_NAME);
chrome.storage.sync.set({ELEMENT_NAME_STR: ELEMENT_DATA });
}
although this has also proven unsuccessful. What am I missing?