gpt4 book ai didi

javascript - 如何将值存储在数组中并在 Chrome 扩展存储中的每个 session 中重用它?

转载 作者:行者123 更新时间:2023-12-03 06:36:35 28 4
gpt4 key购买 nike

我正在尝试用用户点击的(用户的)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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com