0

This code works perfectly

   chrome.storage.sync.get("test", function (array){
      var newArray = array["test"];
      newArray.push("newValue");

      chrome.storage.sync.set({"test": newArray});
   });

But this code does not work

      var key = "test";
      chrome.storage.sync.get(key, function (array){
      var newArray = array[key];
      newArray.push("newValue");

      chrome.storage.sync.set({key: newArray});
   });

Why?

Alex
  • 1
  • Globals not allowed? – Tushar Jul 08 '17 at 13:42
  • @wOxxOm: Doh! Of course it's a duplicate. Thank you. – T.J. Crowder Jul 08 '17 at 13:52
  • Since you're using Chrome, you can use the third option in the accepted answer to the linked question, a computed property name: `chrome.storage.sync.set({[key]: newArray});` (note the `[...]` around `key`). See the linked question's answers for why what you did didn't work. – T.J. Crowder Jul 08 '17 at 13:54

0 Answers0