Function

Module: @ember/object
dependentKey
String
propertyKey
String
value
*
returns
ComputedProperty
the filtered array

Filters the array by the property and value.

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { set } from '@ember/object';
import { filterBy } from '@ember/object/computed';

class Hamster {
  constructor(chores) {
    set(this, 'chores', chores);
  }

  @filterBy('chores', 'done', false) remainingChores;
}

let hamster = new Hamster([
  { name: 'cook', done: true },
  { name: 'clean', done: true },
  { name: 'write more unit tests', done: false }
]);

hamster.remainingChores; // [{ name: 'write more unit tests', done: false }]

Classic Class Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import EmberObject from '@ember/object';
import { filterBy } from '@ember/object/computed';

let Hamster = EmberObject.extend({
  remainingChores: filterBy('chores', 'done', false)
});

let hamster = Hamster.create({
  chores: [
    { name: 'cook', done: true },
    { name: 'clean', done: true },
    { name: 'write more unit tests', done: false }
  ]
});

hamster.remainingChores; // [{ name: 'write more unit tests', done: false }]