Reputation: 1141
I'm using the following code to set a key:value to the local storage:
chrome.storage.local.set({"key": value}, null);
What can I do to add multiple values to the key "key"?
Upvotes: 3
Views: 4237
Reputation: 1960
First use the get
method and then use set
inside the get
callback to add your new storage data as a key/value pair to the storage object returned from get
. Example:
chrome.storage.local.get(function(cfg) {
if(typeof(cfg["key"]) !== 'undefined' && cfg["key"] instanceof Array) {
cfg["key"].push("value");
} else {
cfg["key"] = ["value"];
}
chrome.storage.local.set(cfg);
});
Upvotes: 8