title: Javascript how do I save message response for later use
body: <p>I'm learning Chrome Extensions. Here is a script from background.js that will receive the response message from content.js.</p>
  
  <pre><code>function saveCdKey() {
    var cdKeyJson = new Array();
    storageType.set(cdKeySettings, function() {
      chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        chrome.tabs.sendMessage(tabs[0].id, {message: "getCdKeys"}, function(response) {
          //console.log(response.message);
          cdKeyJson = response.message;
        });
      });
  
      console.log(cdKeyJson);
    });
  }
  </code></pre>
  
  <p>Assuming that I always get the message back from the content.js which is an array. I want to save the response.message into the cdKeyJson for later use in the script. However, when I assign it inside the send message function, it will be empty when I call it later. I.e: when I do console.log on cdKeyJson, it's an empty array. I'm still learning JS so is it anyway that I can save the response for later use? Thank you.</p>