title: Save Java script variable to file
body: <p>Is it possible to save the variable "result" to a file on a server like the php line would do?</p>
  
  <p>php:</p>
  
  <pre><code>file_put_contents($file, $result);
  </code></pre>
  
  <p>script:</p>
  
  <pre><code>&lt;script&gt;
  (function() {
      var jsonArr = [];
      var obj = {};
      var rowIx = 0;
      var jsonObj = {};
      var thNum = document.getElementsByTagName('th').length;
      var arrLength = document.getElementsByTagName('td').length;
  
      for(i = 0; i &lt; arrLength; i++){
          if(i%thNum === 0){
              obj = {};
          }
          var head = document.getElementsByTagName('th')[i%thNum].innerHTML;
          var content = document.getElementsByTagName('td')[i].innerHTML;
          obj[head] = content;
          if(i%thNum === 0){
              jsonObj[++rowIx] = obj
          }   
      }           
  
      var result = "&lt;br&gt;"+JSON.stringify({"Values": jsonObj});
      document.write(result);
  })();
  &lt;/script&gt;
  </code></pre>