Check to see if an element exists before passing a value to an array Jquery
<p>Is there a way that I can check if an element exists before passing a value into an array with jquery.</p>

<p>For example I have the following code:</p>

<pre><code>hyperlinks = new Array();
     $(slideshowThumbs).find('.caption').find('a:first').each(function() {
           hyperlinks.push($(this).attr('href'));
     });
</code></pre>

<p>Which passes and stores the values from a list of items and tells me what their href value is.</p>

<p>The problem that I have at the moment, is that if item 2 in my list does not contain a link, the value that is passed over at position 2 is in actual fact the value from item 3 and not 2.</p>

<p>What I want to do is see if there is an a:first inside of the caption container, and if there isnt pass a value to the array in place that I can subsequently do a check on later. in order to retain the list of items in the array the same as the list of items in my list.</p>

<p>Any ideas?</p>

<p>Many thanks</p>

<p><strong>EDIT:</strong>
Thanks for your suggestions, though they didn't work straight off, they did get my brain to engage with what I was trying to do - coding with a cold, not always a good combination.</p>

<p>In any case my solution was as follows:</p>

<pre><code> hyperlinks = new Array();
 $(slideshowThumbs).find('.caption').each(function() {
      var elemExists = $(this).find('a:first');
      if (elemExists) {
          hyperlinks.push($(this).find('a:first').attr('href'));
      }
      else {
          hyperlinks.push('noLink');
      }
  });
</code></pre>

<p>Thanks again!</p>
