#6 Filter Arrays

Emad Ibrahim
Jun 6, 2016 · 1 min read

Let’s say you have a collection of Articles and you want to filter them. One of the easiest way to do this using the built-in computed helpers.

publishedArticles : Ember.computed.filterBy(‘articles’, ‘status’, ‘active’),
draftArticles : Ember.computed.filterBy(‘articles’, ‘status’, ‘draft’),

The above collections will automatically re-compute as the “articles” array changes, so if you change an article status in articles from active to draft, it will reflect accordingly in each computed array, here is an example https://ember-twiddle.com/fa50909f2683d7335fc8b3fb0d9009ab?openFiles=controllers.application.js%2C

Extra

Explore more at http://emberjs.com/api/classes/Ember.computed.html

Originally published at Ember Daily Tips.

Emad Ibrahim

Written by

Husband, Father of Twins, Published Author, Entrepreneur, Passionate Technologist, Programmer and Productivity Nut. more at https://about.me/eibrahim