title: Trying to loop through an array of objects to populate arrays with data in objects
body: <p>I'm writing a node script to gather a bunch of file names and locations over several hard drives. The issue is that I'm trying to dial into the "dirs" array of objects with a loop so instead of having to code for dirs[i].tv, dirs[i].movies, dirs[i].images, etc for each object in the array I'll have an array of ["tv", "movies", "images, "etc"] that's looped through. I ended up with something like "dirs[i].n" with "n" being a variable defined by the loop, but that's the issue that isn't working. Since "n" isn't defined in the object the script is returning an error</p>
  
  <p>Below is the code I'm working with</p>
  
  <pre><code>var dirs = [
      {
          name: "C",
          loc: "C:/",
          tv: undefined,
          movies: undefined,
          images: "Users/'Master William'/Pictures/",
          music: undefined,
          torrents: undefined,
          porn: undefined
      },
      {
          name: "D",
          loc: "D:/",
          tv: "Video/TV/",
          movies: "Video/Movies/",
          images: "images/pics/",
          music: "Music/",
          torrents: "Torrents/",
          porn: undefined
      },
      {
          name: "I",
          loc: "I:/",
          tv: "Users/heliu/Videos/TV/",
          movies: "Users/heliu/Videos/Movies/",
          images: "Users/heliu/Desktop/Will/Pics/",
          music: "Users/heliu/Music/",
          torrents: undefined,
          porn: "Users/heliu/Videos/Pr0n/"
      },
      {
          name: "J",
          loc: "J:/",
          tv: "Video/TV/",
          movies: "Video/Movies/",
          images: "Pics",
          music: "Tunes/",
          torrents: undefined,
          porn: "Pornography/"
      }
  ]
  
  const fs = require("fs");
  var tvArr = [];
  var moviesArr = [];
  var imagesArr = [];
  var musicArr = [];
  var torrentsArr = [];
  var pornArr = [];
  var mediaArr = ["tv", "movies", "images", "music", "torrents", "porn"];
  var arrArr = [tvArr, moviesArr, imagesArr, musicArr, torrentsArr, pornArr];
  
  
  for( var i = 0; i &lt; dirs.length; i++){
      let o = dirs[i].loc;
      for( var j = 0; j &lt; mediaArr.length; j++){
          let n = mediaArr[j];
          if(dirs[i].n !== undefined){
              let x = dirs[i].loc+dirs[i].n;
              fs.readdirSync(x).forEach(file =&gt; {
                  arrArr[j].push(file);
              })
          }
      }
  }
  </code></pre>