ember.jsember-dataember-model

How to access model array by index in Ember


I am unable to access the EmberArray by index in the template. This is part of my route

model(){
  return RSVP.hash({
    games: this.store.findAll('game')
  })
}

And this is part of the template

<div>
  First game: {{model.games.[0].name}}
</div>

There is no output that is rendered. Although if I iterate over it using

{{#each model.games as |game|}}
  <div>{{game.name}}</div>
{{/each}}

This works fine. Any idea what I might be doing wrong, or what I should do different ?

Thanks


Solution

  • You can use firstObject method.

    {{model.games.firstObject.name}}