In my project I need to access objects properties and nested objects properties and save them to localStorage, and be able to retrieve them individually and replace the current values with the stored ones, but I don't know how to automate that with (for example) a for-in loop.
The saving part works well, but as you can see, i'm quite stuck with the load part. I thought about accessing the property with window["propertyNameAsSring"], but i learned that you can only access global vars and not their properties through the window object.
Tell me if you need any clarification !
var files = {
paramsToSave: {
"game_pageID": game.pageID,
"game_page_sceneID": game.page.sceneID,
"events": Events,
"time_hours": time.hours,
"time_minutes": time.minutes,
"time_daysPlayed": time.daysPlayed,
},
save() {
for (param in this.paramsToSave) {
localStorage[`save_${param}`] = JSON.stringify(this.paramsToSave[param]);
}
},
load() {
// ?
// window[this.paramsToSave[param]] = JSON.parse(localStorage[`save_${param}`]);
}
};
var game = {
..
}
var time = {
..
}
var Events = {
..
}
this.paramsToSave[param] = JSON.parse(...)?game.pageID = getStored("pageID");then?