title: Scraping URLs from a web page with Node.js
body: <p>I'm trying to scrape all URLs from a website and put them into an array. I have a question about an array index. If I add an index number like 2 into array[2], the command line replies with "undefined". If I remove the index and print the whole array, it prints all the URLs line by line. I want each URL to be its own index like:</p>
  
  <ul>
  <li>array[0] = First URL found</li>
  <li>array[1] = Second URL found</li>
  <li>array[2] = Thirs URL found etc.</li>
  </ul>
  
  <p>Can anyone point me in the right direction? Thank you.  </p>
  
  <pre><code>  var request = require('request');
      var cheerio = require('cheerio');
  
     var url = 'http://www.hobo-web.co.uk/';
  
      request(url, function(err, resp, body){
        $ = cheerio.load(body);
        links = $('a'); //use your CSS selector here
        $(links).each(function(i, link){
          var array = $(link).attr('href');
          console.log(array[2]);
  
        });
      });``
  </code></pre>