Ember.EnumerableUtils Namespace packages/ember-metal/lib/enumerable_utils.js:10

Defines some convenience methods for working with Enumerables. Ember.EnumerableUtils uses Ember.ArrayPolyfills when necessary.

Show:

Methods

Show:

addObject

(array, item)

Adds an object to an array. If the array already includes the object this method has no effect.

Parameters:

array Array
The array the passed item should be added to
item Object
The item to add to the passed array

Returns:

'undefined'

deprecateProperty

(object, deprecatedKey, newKey) private
Defined in packages/ember-metal/lib/deprecate_property.js:12
Available since 1.7.0

Used internally to allow changing properties in a backwards compatible way, and print a helpful deprecation warning.

Parameters:

object Object
The object to add the deprecated property to.
deprecatedKey String
The property to add (and print deprecation warnings upon accessing).
newKey String
The property that will be aliased.

filter

(obj, callback, thisArg) Array
Defined in packages/ember-metal/lib/enumerable_utils.js:48
Available since 1.4.0

Calls the filter function on the passed object with a specified callback. This uses Ember.ArrayPolyfill's-filter method when necessary.

Parameters:

obj Object
The object to call filter on
callback Function
The callback to execute
thisArg Object
Value to use as this when executing *callback*

Returns:

Array
An array containing the filtered values

forEach

(obj, callback, thisArg)

Calls the forEach function on the passed object with a specified callback. This uses Ember.ArrayPolyfill's-forEach method when necessary.

Parameters:

obj Object
The object to call forEach on
callback Function
The callback to execute
thisArg Object
Value to use as this when executing *callback*

indexOf

(obj, callback, index)

Calls the indexOf function on the passed object with a specified callback. This uses Ember.ArrayPolyfill's-indexOf method when necessary.

Parameters:

obj Object
The object to call indexOn on
callback Function
The callback to execute
index Object
The index to start searching from

indexesOf

(obj, elements) Array

Returns an array of indexes of the first occurrences of the passed elements on the passed object.

1
2
3
4
5
 var array = [1, 2, 3, 4, 5];
 Ember.EnumerableUtils.indexesOf(array, [2, 5]); // [1, 4]

 var fubar = "Fubarr";
 Ember.EnumerableUtils.indexesOf(fubar, ['b', 'r']); // [2, 4]

Parameters:

obj Object
The object to check for element indexes
elements Array
The elements to search for on *obj*

Returns:

Array
An array of indexes.

intersection

(array1, array2) Array

Calculates the intersection of two arrays. This method returns a new array filled with the records that the two passed arrays share with each other. If there is no intersection, an empty array will be returned.

1
2
3
4
5
6
7
8
9
var array1 = [1, 2, 3, 4, 5];
var array2 = [1, 3, 5, 6, 7];

Ember.EnumerableUtils.intersection(array1, array2); // [1, 3, 5]

var array1 = [1, 2, 3];
var array2 = [4, 5, 6];

Ember.EnumerableUtils.intersection(array1, array2); // []

Parameters:

array1 Array
The first array
array2 Array
The second array

Returns:

Array
The intersection of the two passed arrays.

map

(obj, callback, thisArg) Array

Calls the map function on the passed object with a specified callback. This uses Ember.ArrayPolyfill's-map method when necessary.

Parameters:

obj Object
The object that should be mapped
callback Function
The callback to execute
thisArg Object
Value to use as this when executing *callback*

Returns:

Array
An array of mapped values.

removeObject

(array, item)

Removes an object from an array. If the array does not contain the passed object this method has no effect.

Parameters:

array Array
The array to remove the item from.
item Object
The item to remove from the passed array.

Returns:

'undefined'

replace

(array, idx, amt, objects) Array

Replaces objects in an array with the passed objects.

1
2
3
4
5
6
7
8
  var array = [1,2,3];
  Ember.EnumerableUtils.replace(array, 1, 2, [4, 5]); // [1, 4, 5]

  var array = [1,2,3];
  Ember.EnumerableUtils.replace(array, 1, 1, [4, 5]); // [1, 4, 5, 3]

  var array = [1,2,3];
  Ember.EnumerableUtils.replace(array, 10, 1, [4, 5]); // [1, 2, 3, 4, 5]

Parameters:

array Array
The array the objects should be inserted into.
idx Number
Starting index in the array to replace. If *idx* >= length, then append to the end of the array.
amt Number
Number of elements that should be removed from the array, starting at *idx*
objects Array
An array of zero or more objects that should be inserted into the array at *idx*

Returns:

Array
The modified array.