2

I'm trying to store some nested arrays in a Chrome extension via the Chrome storage API, but when I try to retrieve them, some of the arrays come back as "null" rather than filled with what I originally entered. The following code is a pretty basic approximation of what I'm trying to do; the "savedarray" gets build just fine, and is fine when it goes into storage > [Array[4], Array[4]] , but when it comes back I get > [Array[4], null].

counter = 0;

matrix = [0,1,2,3];
savedarray = new Array();

savedarray[0] = matrix;
savedarray[1] = matrix;

console.log(savedarray)

document.onclick = storagefunction

function storagefunction(){
  counter += 1;
  if(counter == 1){
    chrome.storage.local.set({'stacktest': savedarray}, function() {
    console.log(savedarray)});  
  }
  else{
    chrome.storage.local.get('stacktest', function (result){
    console.log(result.stacktest)});
  }

}

It doesn't seem like it has anything to do with timing, but I can't figure out why on earth my arrays are disappearing into thin air like this.

4

0 回答 0