sainture
4/6/2017 - 11:45 PM

Iteration Methods (arrays & objects)

Iteration Methods (arrays & objects)

// angular.forEach   - used to iterate over a collection (object or array)

// Example object
var values = {name: 'misko', gender: 'male'};
  angular.forEach(values, function(value, key) {
  console.log('key: ' + key + 'value: ' + value);
  })

// Example array
var array = [{name:'1',age:20}, {name:'2', age:21}];
angular.forEach(array, function (obj, index) {
  // do something with obj
});


/*
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, obj), where value is the value of an object property or an array element,
key is the object property key or array element index and obj is the obj itself. 
Specifying a context for the function is optional.
*/