summaryrefslogtreecommitdiffstats
path: root/3rdparty/js/angular-1.0.2/docs/partials/api/angular.forEach.html
blob: 2dd89a8baae2e103d16851c39c64155b09d12b16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<h1><code ng:non-bindable="">angular.forEach</code>
<span class="hint">(API in module <code ng:non-bindable="">ng</code>
)</span>
</h1>
<div><h2 id="Description">Description</h2>
<div class="description"><p>Invokes the <code>iterator</code> function once for each item in <code>obj</code> collection, which can be either an
object or an array. The <code>iterator</code> function is invoked with <code>iterator(value, key)</code>, where <code>value</code>
is the value of an object property or an array element and <code>key</code> is the object property key or
array element index. Specifying a <code>context</code> for the function is optional.</p>

<p>Note: this function was previously known as <code>angular.foreach</code>.</p>

<pre class="prettyprint linenums">
     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']);
   </pre></div>
<h2 id="Usage">Usage</h2>
<div class="usage"><pre class="prettyprint linenums">angular.forEach(obj, iterator[, context]);</pre>
<h3 id="Parameters">Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">obj – {Object|Array} – </code>
<p>Object to iterate over.</p></li>
<li><code ng:non-bindable="">iterator – {Function} – </code>
<p>Iterator function.</p></li>
<li><code ng:non-bindable="">context<i>(optional)</i> – {Object=} – </code>
<p>Object to become context (<code>this</code>) for the iterator function.</p></li>
</ul>
<h3 id="Returns">Returns</h3>
<div class="returns"><code ng:non-bindable="">{Object|Array}</code><p>Reference to <code>obj</code>.</p></div>
</div>
</div>