Ivan
Ivan

Reputation: 380

How do I update a certain value in LocalStorage inside a nested object?

I set it like this:

chrome.storage.local.set({
    myState: {
        data: {
            website: "google.com",
            visited: false,
            count: 0
        }
    }
})

If I want to change myState.data.visited to true, what should I do?

Upvotes: 1

Views: 1420

Answers (1)

jakobinn
jakobinn

Reputation: 2032

You need to get the data, change it and save it again.

    chrome.storage.local.get('storageKey', function(result) {
      //data.visited will be in the result object for a specific key. You can change data.visited 
      //to be true here. After changing it to true you can save it again under 
      //the key 'storageKey' or any key you like.

      chrome.storage.local.set({storageKey: result});
    });

Upvotes: 3

Related Questions