AngularJS | angular.forEach() Function
The angular.forEach() Function in AngularJS is used to iterate through each item in an array or object. It works similar to the for loop and this loop contains all properties of an object in key-value pairs of an object.
Syntax:
angular.forEach(object, iterator, [context])
Parameter Values:
- object: It refers to the object to be iterated.
- iterator: It refers to the iterator function(value, key, obj).
- context: This is optional. It refers to the object which becomes context for iterator function.
Example:
<html> <head> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"> </script> <title>angular.forEach()</title> </head> <body ng-app="app" ng-cloak style="padding:30px"> <h1 style="color:green">GeeksforGeeks</h1> <h2>angular.forEach()</h2> <p>Searching techniques:</p> <div ng-controller="geek"> <div ng-repeat="name in names"> <ul><li>{{name}}</li></ul> </div> </div> <script> var app = angular.module("app", []); app.controller('geek', ['$scope', function ($scope) { $scope.names = []; var values = [ {name: 'Binary Search'}, {name: 'Linear Search'}, {name: 'Interpolation Search'} ]; angular.forEach(values, function (value, key) { $scope.names.push(value.name); }); }]); </script> </body> </html> |
chevron_right
filter_none
Output:

Recommended Posts:
- PHP | imagecreatetruecolor() Function
- p5.js | year() function
- D3.js | d3.utcTuesdays() Function
- PHP | Ds\Sequence last() Function
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- D3.js | d3.map.set() Function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- D3.js | d3.bisectLeft() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- AngularJS | ng-show Directive
- PHP | is_numeric() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



