# angular.forEach

Work in Progress This page is currently being revised. It might be incomplete or contain inaccuracies.

## Description

Invokes the `iterator` function once for each item in `obj` collection. The collection can either be an object or an array. The `iterator` function is invoked with `iterator(value, key)`, where `value` is the value of an object property or an array element and `key` is the object property key or array element index. Optionally, `context` can be specified for the iterator function.

Note: this function was previously known as `angular.foreach`.

         var values = {name: 'misko', gender: 'male'};
         var log = [];
         angular.forEach(values, function(value, key){
           this.push(key + ': ' + value);
         }, log);
         expect(log).toEqual(['name: misko', 'gender:male']);

## Usage

    angular.forEach(obj, iterator, context);

### Parameters

- `obj – {Object|Array} –`

  Object to iterate over.

- `iterator – {function()} –`

  Iterator function.

- `context – {Object} –`

  Object to become context (`this`) for the iterator function.

### Returns

`{Objet|Array}` –

Reference to `obj`.