title: Javascript Web Workers Modifying Global Object
body: <p>The documentation on JavaScript Web Workers is daunting. Basically, I have a heavy loop that causes the browser to hang a little bit. If I could offload that heavy loop onto another CPU core, then I could hopefully take some weight off the application and get it to run more smoothly. I am trying to modify a global variable using a simple loop:</p>
  
  <pre><code>var globalarr;
  
  function webWorkerOp(CSV) {
      var lines = CSV.split("%");
      var items, obj, arr = [];
  
      for (var x = 0, len = lines.length; x &lt; len; x++) {
          items = lines[x].split(",");
          obj = {};
          obj.a = +items[0];
          obj.b = +items[1];
          arr[x] = obj;
      }
  
      globalarr = arr;
  }
  </code></pre>
  
  <p>How would I wrap this loop operation up into a web worker without causing a conflict with the primary program running code? The modification of the global variable will sure be a problem, I would think. Is it even possible to assign the new array to the globalarr var? Help is appreciated. Thanks!</p>