Why {{array.[index]}} not working

{{#each array as |item index|}}


It can not work.

Unless replacing index with explicit number



Do I miss something?

Ember does not support all of handlebars syntax, this is one example.

You can do this with a helper though, simple version might look like:

App.ObjectAtHelper = Ember.Helper.helper(function([ array, index]) {
  return array[index];

JSBin Demo


What about

{{#each array key="@index" as |item|}}


Thank you.

Just think there should be a built-in way doing that thing.

Customize helper is very useful.

But I think ember.js should include those very very generic helpers to official helpers. It’s better than that everyone has to do this.

Try the get helper which has become available in Ember 2.0:

{{get anotherArray index}}
1 Like

A related open issue in htmlbars:

If you get an error about index needing to be a string, simply do this: (get items (concat index ""))