#84 empty arrays

Want to check if an array is empty in your templates, for example:

{{if hasNoComments}}
<div>No comments</div>
{{/if}}

There are many ways to do this, one way would be check the array length e.g.

hasNoComments: Ember.computed('comments.length',() => {
if(!this.get('comments')) return true;
return this.get('comments.length') < 1;
}

Or even better, you can use the empty computed helper in your controller to easily check if your comments array is empty with:

hasNoComments: Ember.computed.empty('comments')

Originally published at Ember Daily Tips.