I am working in Javascript and creating an offline application.
I have a very large array, over 10mb. I need to save elements from the array where a user has made a change, but writing / reading the array to disk is too slow.
I would like to create a second array that holds only the changes made by the user, so I can save that smaller array and then when I need to load changes it can mirror its changes to the large array.
For example:
lib[x][1][y][6] = "no";
libVars[x][1][y][6] = "no";
libVars would simply hold the element changes in lib and would not be the same size as the large array lib as the user will only interact with a small portion of the large array.
Obviously this doesn't work, as libVars doesn't have the same structure as lib, and if it did it would also take up a lot of memory (i think so anyways!)
I would then like to loop through libVars and update lib at the same element points where the changes have been saved in libVars.
Is there a way to save some type of pointer to a location within lib that I could store in libVars with the associated element value?
Any help would be much appreciated.
Thanks.
======================
Sample of my large array
var lib = [
[241,[[221119,"sample data","sample","no","no",131,"no"],
[221121,"sample2 data","sample2","no","no",146,"no"],
[221123,"sample3 data","sample3","no","no",28,"no"],
[221626,"sample4 data","sample4","no","no",26,"no"],
[221628,"sample5 data","sample5","no","no",88,"no"]]],
[330,[[305410,"2sample data","sample 2b","no","no",197,"no"],
[305412,"2sample 2 data","sample2 2b","no","no",147,"no"],
[305414,"3sample 2 data","sample3 2b","no","no",10,"no"] ...
Attempt at solution posted by Z-Bone
I have added the tempLib var, but I don't see how you eventually update the actual lib object
Object.entries(libVars).forEach(([path, value]) => {
var tempLib = lib;
var pathParts = path.split('#');
pathParts.forEach((pathPart, index) => {
if (index == pathParts.length-1) {
tempLib[pathPart] = value;
} else {
//I don't fully track what you are doing here.
//I assume you are building the array path, but to me it looks like
// it's getting wiped out and not built upon?
tempLib = tempLib [pathPart];
}
});
});