Friday, January 1, 2016

Angularjs : foreach loop

angular.forEach() invokes the iterator function once for each item in obj collection, which can be either an object or array.

Syntax of ForEach loop in AngularJS:
angular.forEach($scope.data, function(value, key){});

Here are few example of angular.forEach() function:
1. Object Properties iteration:
   angular.forEach() function can be used to iterate of each property of object.

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

2. Object Collection Iteration:
angular.forEach() function can be used to iterate of each item of collection.

var values = [
  { "Name" : "Thomas", "Password" : "thomasTheKing" },
  { "Name" : "Linda", "Password" : "lindatheQueen" }
]

angular.forEach(values, function(value, key)
 {
  console.log ('Index:' + value.Nam);
  console.log ('Name: ' + value.Name);
  console.log ('Password: ' + value.Password);
});

Here key will work as Index of object in collection

Other blogs related to AngularJs :

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...