angular-foreach-4

 

In this example of angular.foreach, it will push both key and value i.e property name and its value in 'tempArr'. See the code snippet:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="forEachController"> {{tempArr}} </div> </body> </html> <script> var app = angular.module("app", []); app.controller('forEachController', ['$scope', function ($scope) { var values = { Name: 'Java', Location: 'IN', Date: '28/12/2015', Phone: '9855514371' }; $scope.tempArr = []; angular.forEach(values, function (value, key) { $scope.tempArr.push(key + ': ' + value); }); }]); </script>
Output