chrome sync storage to store and update array

后端 未结 1 1010
心在旅途
心在旅途 2021-01-05 05:20

is it possible to store array in chrome storage sync and retrieve them ?

var uarray = [abc,def,ghi];

Is it possible to update the stored ar

相关标签:
1条回答
  • 2021-01-05 05:43

    You can read the existing values, append the new value and store back.

    Following sample code should allow you to add newArrEntry into existing array stored in chrome.storage.sync

    chrome.storage.sync.get(["storagekey"], function(result) {
            var array = result[storagekey]?result[storagekey]:[];
    
            array.unshift(newArrEntry);
    
            var jsonObj = {};
            jsonObj[storagekey] = array;
            chrome.storage.sync.set(jsonObj, function() {
                console.log("Saved a new array item");
            });
        });
    
    0 讨论(0)
提交回复
热议问题