title: Selecting arrays with specific element values
body: <p>This is driving me nuts, I've been trying to figure out how to do this one thing for hours now.</p>
  
  <p>What I want to do is select all array items that have a specific value. This is easiest to explain by example:</p>
  
  <p>I have an array, called <code>media[]</code>. It holds ALL of the media in my media gallery. It has two properties of note: <code>path</code> and <code>gallery</code>, or <code>media[x][0]</code> and <code>media[x][1]</code>.</p>
  
  <p>I want to select all media objects that belong in a certain gallery, and then add them to that gallery. That's where I'm struggling and it's driving me mad.</p>
  
  <p>Here are my fumbled attempts at trying to do this... this is some seriously messy code (and mostly pointless), I'm just providing it so you can get a sense of how clueless I am about this. Please note that NONE of the code I have right now actually tries to <strong>do</strong> anything; everything I've done so far ends up as a broken <code>for</code> or <code>while</code> loop that either does nothing or crashes Chrome.</p>
  
  <pre><code>// this function is meant to return an array of all media items
  // that belong in a certain gallery... didn't get that far because
  // the loops tripped me up
  function getTheMedia (galNum) {
      var output = [];
      for (var i = 0; i &lt; media.length; ++i) {
          // I tried using an if statement here to check if the
          // media[i][1] == galNum, and if so, add it to the output
          // but that didn't work
          output.push(media[i]);
      }
      return output;
  }
  
  // this function was actually my first attempt but I kept running into
  // the same issue as above
  function fillGal () {
      /*
      var output = [];
      for (var i = 0; i &lt; Gallery.length; ++i) {
          output.push(Gallery[i]);
      }
      */
      var output = [];
      var i = 0;
      while (i &lt; media.length) {
          output.push(i);
          i++;
      }
      console.log(output);
  }
  </code></pre>
  
  <p>Seeing as I'm kind of burnt out and frustrating with running in circles (...loops? aha...), all I'm really looking for is a way to select only those specific array items as specified above. Everything else (adding them to the Gallery, etc) I can figure out myself.</p>
  
  <p>Otherwise I'm just going to have to go back to the old way: define separate <code>media[]</code>arrays for each "gallery" (<code>mediaThisGallery</code>, <code>mediaThatGallery</code>, etc), and then combine them all at the end to get "<code>allMedia</code>". Only reason I don't want to do that is because I want to be able to change which gallery a media item belongs to... this HAS to be possible, right?</p>
  
  <p>Thanks in advance! Sorry for the scatter-brainedness. I also apologize if the title is a bit off.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>var media = [];
  
  media[0] = ['0.png', 0, 'index'];
  media[1] = ['0.png', 0];
  
  media[2] = ['new/316.png', 1, "316"];
  media[3] = ['new/kitties.jpg', 1, "D'aww kitties!!"];
  media[4] = ['new/home.jpg', 1, "\"I'm Going Home\""];
  media[5] = ['new/3.mp4', 1, "Crucible Carnage"];
  media[6] = ['new/942.jpg', 1, "this is straight for testing purposes like omg long ass title lol"];
  media[7] = ['new/boom.mp4', 1, "Maximum Efficiency"];
  media[8] = ['new/42.jpg', 1, "Moo"];
  
  // this is only included as a quick fix so my working code doesn't break
  // as my "production" code is using multiple arrays; Media is used
  // to store only the selected array (current Gallery)
  // in other words, ignore this
  var Media = [];
  Media = media;
  
  var Gallery = [];
  Gallery[0] = [mediaRoot, "index", media ];
  Gallery[1] = [mediaRoot, "new", Media ];
  </code></pre>
  
  <p>It's pretty arbitrary atm.</p>
  
  <p>Note that the main reason I'm converting from multiple arrays to a single array is that eventually, I plan to expand this app and I thought it made more sense to store ALL media in a single "database".</p>