title: How to check if an array index exists using Ruby and/or Rails
body: <p>Is there a Ruby (preferably) or Rails way to check if the second index of an array exists?</p>
  
  <p>In my Rails (4.2.6) app I have the following code in my view that shows the first two thumbnails for an array of photos:</p>
  
  <pre><code>&lt;% if array.photos.any? %&gt;
    &lt;%= image_tag array.photos.first.image.url(:thumb) %&gt;
    &lt;%= image_tag array.photos[1].image.url(:thumb) %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>However if there is no second item in the array, then there is an error</p>
  
  <p>I've tried the following <code>if</code> statements to make the rendering of the second thumbnail conditional, but they don't work:</p>
  
  <pre><code>&lt;% if array.photos.include?(1) %&gt;
  &lt;% if array.photos.second? %&gt;
  &lt;% if array.photos[1]? %&gt;
  &lt;% if array.photos[1].any? %&gt;
  </code></pre>
  
  <p>I figured that another way to get what I want would be to simply check the length of the array</p>
  
  <p>Still I was wondering if Ruby (or Rails) had a method or way to check if a specific index in an array exists or not.  Thanks in advance</p>
  
  <p>EDIT: To clarify I just want to show the first two thumbnails in the array, if any</p>