Improve this Doc View Source angular.forEach
- function in module ng
Invokes the iterator
function once for each item in obj
collection, which can be either 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. Specifying a context
for the function is optional.
It is worth noting that .forEach
does not iterate over inherited properties because it filters using the hasOwnProperty
method.
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]);
Arguments
Param | Type | Details |
---|---|---|
obj | Object Array | Object to iterate over. |
iterator | Function | Iterator function. |
context (optional) | Object | Object to become context ( |
Returns
Object Array
|
Reference to |
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.2.32/docs/api/ng/function/angular.forEach