How to use foreach loop in angularjs with key and value of object

Summons the iterator work once for every thing in obj gathering, which can be either an article or an exhibit. The iterator capacity is conjured with iterator(value, key, obj), where quality is the estimation of an item property or an exhibit component, key is the article property key or cluster component file and obj is the obj itself. Determining a setting for the capacity is discretionary.

It is important that .forEach does not emphasize over acquired properties since it channels utilizing the hasOwnProperty strategy.

Not at all like ES262's Array.prototype.forEach, giving "indistinct" or "invalid" qualities for obj won't toss a TypeError, yet rather simply give back the worth gave.

<script>
  var myFirstApp = angular.module('myFirstApp', []);
  myFirstApp.controller('myCtrl', function($scope) {
  // create new object and store record in the object
  $scope.object = [
   {
    'name': 'Groceries'
    'parent': 'expence'
   },
   {
    'name': 'rent'
    'parent': 'expence'
   }
  ];
  // create new function which exicute forech loop
  $scope.foreachLoop = function ( $object ){
   angular.forEach( $object , function(arrayValue , key) { 

    console.log( "Object key "+key + " Object value "+arrayValue );
    
   }, log); 
  };
  // function call
  $scope.foreachLoop(  $scope.object );   
  });
</script>

Share this

Related Posts

Previous
Next Post »