Function
uniq (propertyKey) ComputedProperty public
Module:
@ember/object
Defined in packages/@ember/object/lib/computed/reduce_computed_macros.js:767
import { uniq } from '@ember/object/computed'; |
- propertyKey
- String
- returns
- ComputedProperty
- computes a new array with all the unique elements from the dependent array
A computed property which returns a new array with all the unique elements from one or more dependent arrays.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import { set } from '@ember/object'; import { uniq } from '@ember/object/computed'; class Hamster { constructor(fruits) { set(this, 'fruits', fruits); } ('fruits') uniqueFruits; } let hamster = new Hamster([ 'banana', 'grape', 'kale', 'banana' ]); hamster.uniqueFruits; // ['banana', 'grape', 'kale'] |
Classic Class Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import EmberObject from '@ember/object'; import { uniq } from '@ember/object/computed'; let Hamster = EmberObject.extend({ uniqueFruits: uniq('fruits') }); let hamster = Hamster.create({ fruits: [ 'banana', 'grape', 'kale', 'banana' ] }); hamster.uniqueFruits; // ['banana', 'grape', 'kale'] |