Ember.EnumerableUtils Class
Defines some convenience methods for working with Enumerables.
Ember.EnumerableUtils
uses Ember.ArrayPolyfills
when necessary.
Item Index
Methods
addObject
-
array
-
item
Adds an object to an array. If the array already includes the object this method has no effect.
Parameters:
-
array
ArrayThe array the passed item should be added to
-
item
ObjectThe item to add to the passed array
Returns:
'undefined'
filter
-
obj
-
callback
-
thisArg
Calls the filter function on the passed object with a specified callback. This
uses Ember.ArrayPolyfill
's-filter method when necessary.
Parameters:
-
obj
ObjectThe object to call filter on
-
callback
FunctionThe callback to execute
-
thisArg
ObjectValue to use as this when executing callback
Returns:
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
ObjectThe object to call forEach on
-
callback
FunctionThe callback to execute
-
thisArg
ObjectValue to use as this when executing callback
indexesOf
-
obj
-
elements
Returns an array of indexes of the first occurrences of the passed elements on the passed object.
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
ObjectThe object to check for element indexes
-
elements
ArrayThe elements to search for on obj
Returns:
An array of indexes.
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
ObjectThe object to call indexOn on
-
callback
FunctionThe callback to execute
-
index
ObjectThe index to start searching from
intersection
-
array1
-
array2
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.
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
ArrayThe first array
-
array2
ArrayThe second array
Returns:
The intersection of the two passed arrays.
map
-
obj
-
callback
-
thisArg
Calls the map function on the passed object with a specified callback. This
uses Ember.ArrayPolyfill
's-map method when necessary.
Parameters:
-
obj
ObjectThe object that should be mapped
-
callback
FunctionThe callback to execute
-
thisArg
ObjectValue to use as this when executing callback
Returns:
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
ArrayThe array to remove the item from.
-
item
ObjectThe item to remove from the passed array.
Returns:
'undefined'
replace
-
array
-
idx
-
amt
-
objects
Replaces objects in an array with the passed objects.
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
ArrayThe array the objects should be inserted into.
-
idx
NumberStarting index in the array to replace. If idx >= length, then append to the end of the array.
-
amt
NumberNumber of elements that should be removed from the array, starting at idx
-
objects
ArrayAn array of zero or more objects that should be inserted into the array at idx
Returns:
The modified array.