title: Performing async function on each element in array?
body: <p>So I have an array of URLs</p>
  
  <p>I want to pull the html from each (for which I am using <a href="https://github.com/danwrong/restler" rel="nofollow">restler</a> node.js library)</p>
  
  <p>Then select some of that data to act on via jquery (for which I am using <a href="https://github.com/MatthewMueller/cheerio" rel="nofollow">cheerio</a> node.js library)</p>
  
  <p>The code I have works, but duplicates the pulled data by however many URLS there are.
  I am doing this in Node but suspect it's a generalized Javascript matter that I don't understand too well.</p>
  
  <pre><code>url.forEach(function(ugh){
      rest.get(ugh).on('complete', function(data) {
          $ = cheerio.load(data);
          prices.push($(".priceclass").text());
          //i only want this code to happen once per item in url array
          //but it happens url.length times per item
          //probably because i don't get events or async very well
      });
  });
  </code></pre>
  
  <p>So if there are 3 items in the 'url' array, the 'prices' array with the data I want will have 9 items. Which I don't want</p>
  
  <p>--EDIT:</p>
  
  <p>Added a counter to verify that the 'complete' callback was executing array-length times per array item.</p>
  
  <pre><code>x=0;
  url.forEach(function(ugh){
      rest.get(ugh).on('complete', function(data) {
          var $ = cheerio.load(data);
          prices.push($(".priceclass").text());
          console.log(x=x+1);
      });
  });
  </code></pre>
  
  <p>Console outputs 1 2 3 4 5 6 7 8 9</p>
  
  <p>I was thinking that I might be going about this wrong. I've been trying to push some numbers onto an array, and then outside the callbacks do something with that array.</p>
  
  <p>Anyways it seems clear that >1 restler eventlisteners aren't gonna work together at all.</p>
  
  <p>Maybe rephrasing the question would help:
  How would I scrape a number of URLs, then act on that data?</p>
  
  <p>Currently looking into request &amp; async libraries, via code from the extinguished <a href="https://github.com/chriso/node.io" rel="nofollow">node.io library</a></p>