0

I am trying to make a recent system where, when you go to an id of an item it stores when u went to that id, something along the lines of this:

chrome.storage.local.set({
[variable of id]: {
 recentTime: new Date(),
 anotherVariable: "hello world"
}});

The problem is that i want to store 2 instances of history, so I want to add another one like this, this is where the problem appears, the previous keys are gone, since it's a set(), not an add()

chrome.storage.local.set({
[variable of id]: {
 recentTime2: new Date(),
 anotherVariable2: "hello world"
}});

however I can fix this by using chrome.storage.local.get() and doing Object.assign() with both variables when setting, this is a bit of a hassle and isn't very efficient but it's fine, I can deal with it.

but what if, I need to do in objects, something with a longer path like this:

chrome.storage.local.set({
something: {
 // there is a variable here in the storage
 something: {
  // there is a variable here in the storage again
  something: "a"
 }
}
});

And like this it becomes a big hassle, and becomes something hard to deal with. I could potentially do a function that can do this automatically but that is very hard for me.

Is there any other efficient way to do this?

Tom
  • 1
  • 1

0 Answers0