Browser.storage.sync.set nested values

With WebExtensions how can I use browser.storage.sync.set to save a value to a (deeply) nested property in the storage?

Let’s say I have the following storage object:

{
   settings: {
      a: { x: [1,2] },
      x: 0
   }
}

I would like to change the 2. array element in settings.a.x (not to confuse with settings.x!)
how could I accomplish this?

Note: browser.storage.sync.set({ settings: { a: { x: [2,3] }}}) seems to overwrite the whole settings object (deleting settings.x) - and also I would only like to change the array’s 2. element.

You would have to first fetch the value and then set it with the changed data. You can only change top level keys without providing the whole data structure.

1 Like

OK, that’s what I thought. If this is the only way then I will take it ^^
Thank you for the quick answer