API Docs for: 1.0 pre
Show:

Ember.EnumerableUtils Class

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

Methods

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'

filter

(
  • obj
  • callback
  • thisArg
)
Array

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

indexesOf

(
  • obj
  • elements
)
Array

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 Object

    The object to check for element indexes

  • elements Array

    The elements to search for on obj

Returns:

Array:

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 Object

    The object to call indexOn on

  • callback Function

    The callback to execute

  • index Object

    The index to start searching from

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.

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.

  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.