It doesn't work the way it's supposed to

A day or two ago I was working on a side project and ran into an odd solution to a very common problem. In fact the problem is so common, it’s not a problem. Let’s look at a standard Meteor.users() record…

{
  "_id": "aAfSERPtP4AMBitB9",
  "createdAt" "2015-08-04T19:08:21.304Z",
  "services": {
    "password": {
      "bcrypt": "$2a$10$KbMT1PsoozuHlL7cThzeKOtBkhu8Wcl4zDYJUMkzK..plHmNpm0.G"
    },
    "resume": {
      "loginTokens": []
    }
  },
  "emails": [
    {
      "address": "user@somewhere.com",
      "verified": false
    }
  ],
  "profile": []
}

I was building an administrator dashboard and wanted to show a list of all users and their email addresses. Naturally I noticed that the emails property of the user record is an array of objects. Using a typical syntax to display this value I did this:


  {{emails[0].address}}
{% end raw %}

This should have worked because I’m calling the first object in the array by it’s index however, it didn’t work at all. After some toying around and finally giving up and asking on The Meteor Chef slack room I found out that you have to do this:

{% raw %}
  {{emails.[0].address}}

This is saying that emails has a property that is an array with a blank name and that array has an address property. This makes no sense, at all to me, but it works so that is what matters. If anyone can explain why the . is necessary please shoot me an email!

Hope this helps some others if they are struggling to display a user’s email.