title: How to iterate through an array in a sequence using forEach
body: <p>I am using the xdmp.eval function to search and return a document in my final database to use during my harmonization process.</p>
  
  <pre><code>let finalDoc = xdmp.eval(
  "fn.head(cts.search(cts.jsonPropertyValueQuery('Id',id, 
  ['exact']),['unfiltered','score-zero']))",
       {'id':id},
       {"database" : xdmp.database("data-hub-FINAL")});
  </code></pre>
  
  <p>The document is returned as a sequence with this structure: </p>
  
  <pre><code>{"SourceSystemName":"",
    "BatchDtTm":"06/20/2018 15:05:15",
    "SubjectArea":"Customer",
    "DocumentType":"Registration",
     "Id":"100", 
       "Contact":[
         {"CustomerId":"1",
          "FirstName":"",
          "LastName":"",
          "EmailId":""
         },
         {"CustomerId":"2",
          "FirstName":"",
          "LastName":"",
          "EmailId":""
         }            
       ]
  }
  </code></pre>
  
  <p>I need to iterate through each customer in the <strong>Contact</strong> array using <strong>finalDoc.Contact.forEach()</strong>. However, when I use fn.head(finalDoc.toArray()) or fn.head(finalDoc.toObject()) to change the finalDoc sequence to an array, my forEach function fails with the error <strong>"Cannot read property 'forEach' of undefined"</strong>. When I simply just try to output the contact array by doing finalDoc.Contact (or finalDoc[0].Contact), I get a "Null" output.</p>
  
  <p>How do I grab the Contact array out of the sequence and iterate through it using forEach? Thanks!</p>