How to use the variable presentationtitle as key in my else condition within the object given its a string?
I tried if (typeof data.presentations.'(presentationtitle)'
let presentationtitle = 'Test presentation 123'
let variable = {
presentations: {
[presentationtitle] : {
duration: '00:00:00',
}
},
};
chrome.storage.sync.get('presentations', function(data) {
if (typeof data.presentations === 'undefined') {
// if not set then set it
let extensionsettings = {
presentations: {
[presentationtitle] : {
}
},
general: {
setting1: true,
setting2: false
},
};
chrome.storage.sync.set(extensionsettings, () => {
});
}
else {
chrome.storage.sync.get('presentations', function(data) {
if (typeof data.presentations.'(presentationtitle)' === 'undefined') {
// if not set then set it
let presentationtitlesave = {
presentations: {
[presentationtitle] : {
duration: '00:00:00',
}
},
};
chrome.storage.sync.set(presentationtitlesave, () => {
});
}
});
}
Basically I first save an object for extensionsettings (for first time use of the extension opening the popup) and thereafter I want to add presentationtitles into it if they are not present yet (which I extract them from DOM HTML).