I have read several other posts describing dynamic variables, why not to use eval, and how to instead use objects, but I have been unable to apply this to chrome.storage.sync.
Today I do the following to save an array of data to sync storage:
...
// Update the database in the user's storage
chrome.storage.sync.set({ SEARCH_DB: LOCAL_DB }, function () {
// Overwrite Search DB in the user's storage with the LOCAL_DB array;
});
...
Then I retrieve the database from storage with:
...
chrome.storage.sync.get({ SEARCH_DB: [] }, function (data) {
if (data.SEARCH_DB.length > 0) {
var LOCAL_DB = [];
LOCAL_DB = data.SEARCH_DB.concat();
});
...
This all works fine, the problem is that instead of storing to "SEARCH_DB", I want the user to be able to input "USER'S_DB_NAME" and then be able to store that variable in sync:
...
// Update the database in the user's storage
chrome.storage.sync.set({ "USER'S_DB_NAME": LOCAL_DB }, function () {
// Overwrite Search DB in the user's storage with the LOCAL_DB array;
});
...
And later retrieve:
...
chrome.storage.sync.get({ "USER'S_DB_NAME": [] }, function (data) {
if (data."USER'S_DB_NAME".length > 0) {
var LOCAL_DB = [];
LOCAL_DB = data."USER'S_DB_NAME".concat();
});
...
Could someone help me with the code for how I can create the variable to store and retrieve with sync?
Thanks! Jon