title: Array of Hashes in Javascript
body: <p>I'm working with Google sheets and script to write functions that look up data from a table and return the records as a hash. There may be a better way of doing this, but right now, I'm trying to return an array of record hashes, in which the keys are the field names. </p>
  
  <p>What I'm having trouble with is calling a key from an individual record hash from the array. It's just returning 'undefined'. Here's the portion of my test code I've written to look at my application code where I'm having the issue:</p>
  
  <pre><code>function hashArrayTest() {
    var workbookKey = "I blanked this out"
    var tableName = "AttributeChildParentJoin";
    var headerRow = 1;
    var i;
    var attrsJoinObj = new dbEntitySource(workbookKey, tableName, headerRow);
    var OutputHashArray = attrsJoinObj.returnHashItems("Parent Attribute", "Child Attribute", "AESTHETICS");
  
    Logger.log("This is the resulting output array of hashes: ");
  
    for(i=0; i&lt;OutputHashArray.length; i++){
      Logger.log("-------------" + i + "-------------");
      Logger.log(OutputHashArray[i]);
    }
  
    Logger.log("Here are the Parent Attributes from each hash: ");
  
    for(i=0; i&lt;OutputHashArray.length; i++){
      Logger.log("-------------" + i + "-------------");
      Logger.log(OutputHashArray[i]['Parent Attribute']);
      }
    }
  </code></pre>
  
  <p>Here's the source data table: <br /><br />
  <img src="https://i.stack.imgur.com/4jMFZ.png" alt="An image of the data table source">
  <br /><br /><br /></p>
  
  <p>Here is the log of the code output: <br /><br /></p>
  
  <pre><code>[-] This is the resulting output array of hashes:
  [-] -------------0-------------
  [-] {'Date Added'='', 'Child Attribute'='Color', 'Parent Attribute'='AESTHETICS', 'Added by'='', 'ID'='21'}
  [-] -------------1-------------
  [-] {'Date Added'='', 'Child Attribute'='Finish', 'Parent Attribute'='AESTHETICS', 'Added by'='', 'ID'='22'}
  [-] -------------2-------------
  [-] {'Date Added'='', 'Child Attribute'='Material', 'Parent Attribute'='AESTHETICS', 'Added by'='', 'ID'='23'}
  [-] -------------3-------------
  [-] {'Date Added'='', 'Child Attribute'='VBL Styling Adherence', 'Parent Attribute'='AESTHETICS', 'Added by'='', 'ID'='24'}
  [-] Here are the Parent Attributes from each hash: 
  [-] -------------0-------------
  [-] undefined
  [-] -------------1-------------
  [-] undefined
  [-] -------------2-------------
  [-] undefined
  [-] -------------3-------------
  [-] undefined
  </code></pre>
  
  <p>In this output, it looks as though I have successfully created an array of hashes, although I am unable to call the ['Parent Attribute'] key from each hash.</p>
  
  <p>I wrote a really simple function to test out my issue with arrays of hashes, but this time I am successful. =><br />
  Here's the code:</p>
  
  <pre><code>function rawHashTest(){
   var recordHash1 = {};
   recordHash1['car'] = 45;
   recordHash1['chicken'] = "ten";
  
   var recordHash2 = {};
   recordHash2['red'] = 30;
   recordHash2['sticks'] = "blue";
  
   Logger.log(recordHash1);  
   Logger.log(recordHash1['car']);
  
   var hashArray = new Array();
   hashArray = [recordHash1, recordHash2];
  
   Logger.log(hashArray);
   Logger.log(hashArray[0]);
   Logger.log(hashArray[0]["car"]); 
  }
  </code></pre>
  
  <p>Here's the log:<br /></p>
  
  <pre><code>[-] {chicken=ten, car=45.0}
  [-] 45.0
  [-] [{chicken=ten, car=45.0}, {red=30.0, sticks=blue}]
  [-] {chicken=ten, car=45.0}
  [-] 45.0
  </code></pre>
  
  <p>I can't figure out why I am able to call a hash key value from one of the hashes in the array in my simple test code, but not when I'm testing my application code. I've tried this all different ways and I've checked for leading and trailing spaces. What am I missing here? </p>
  
  <p>Thank you,
  Nicholas Kincaid</p>