title: Parsing arrays within array for email in Node.js
body: <p>I am submitting an array that contains nested arrays from Angular to a server running Node.js. I would like to parse each field so I can include it in a confirmation email. I'm not sure how to get the key/values from the array and put them in the email body. </p>
  
  <p>I've tried <code>var email = req.body.email</code> for the items one level deep and <code>var cost = req.body.detail.cost</code> for the nested items two levels deep, but those don't seem to work. </p>
  
  <p>Any suggestions?</p>
  
  <p>Here's the Javascript:</p>
  
  <pre><code>router.post('/', function(req, res) {
    if (err) {
     res.status(402).send(err.message);
  }
  
  else {
    console.log(JSON.stringify(req.body, null, 2));
    var data = {
      from: storefront@example.com,
      to: email,
      subject: 'Your Order Confirmation',
      text: 'Thank you for your order. Below is your invoice:\n\n'+
            'Name: '+ firstName + ' ' + lastName +
            'Address: ' + address + ', ' + city + ', ' + state.code +'\n\n'+
  
            'Item    Description     Cost\n\n'+
            item +   description  +  cost 
  // want to add the item, description, and cost for each item ordered
  // . . . 
  
  var mailgun = new Mailgun({apiKey: api_key, domain: domain});
  
    mailgun.messages().send(data, function (err, body) {
  
      if (err) {
  
        console.log('error');
      }
     else {
  
        console.log('email sent!');
  
      }
    })
  }; 
  </code></pre>
  
  <p>This is what the array looks like this:</p>
  
  <pre><code>[
    [
      {
       "firstName": "John",
       "lastName": "Doe",
       "address": "555 Broadway",
       "city": "New York",
       "email": "john@example.com",
       "phone": "2125551212",
       "state": {
         "code": "NY",
         "state": "New York"
      },
       "timestamp": {
         "addedAt": 1443911047642
     },
      "zip": "10001",
      "$id": "-K-jnWa0IBiGCAInbaIr",
    }
  ],
  [
    {
      "item": "Pants",
      "description": "Wranglers",
      "timestamp": {
        "addedAt": 1443911007264
     },
      "detail": {
        "cost": 60,
        "size": "36"
     },
      "$id": "-K-jnMj64LS-XMM18J-8",
  },
  {
     "item": "Pants",
     "description": "Levi's",
     "timestamp": {
       "addedAt": 1443911018026
    },
    "detail": {
      "cost": 80,
      "size": "33"
    },
     "$id": "-K-jnPMJDLJMKIH4rAUe",
  
    }
   ]
  ]
  </code></pre>