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 :
1 comment:
SAP Grc online courses
SAP Secrity online courses
oracle sql plsql online courses
go langaunage online courses
azure online courses
java online courses
salesforce online courses
hadoop online courses
Post a Comment