我正在尝试用用户点击的(用户的)id 创建一个数组。其功能是:
$('button').click(function(){
var value = $('this').parents('.username').attr('id')
// How to create array in the chrome storage?
// How can I push the value to an array and create a permanent one?
})
最佳答案
您可以尝试以下操作:
chrome.storage.local.get("myArray", function(dataStored) { //load your saved array, if it exists
var workingArray = dataStored.myArray || []; //if it doesn't exist, create an empty one
workingArray.push(value); //add the value just obtained
chrome.storage.local.set({myArray:workingArray}); //save the array.
});
关于javascript - 如何将值存储在数组中并在 Chrome 扩展存储中的每个 session 中重用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38173372/