The angular.forEach
accepts an object and an iterator function. It then runs the iterator function over each enumerable property/value of the object. This function also works on arrays.
Like the JS version of Array.prototype.forEach
The function does not iterate over inherited properties (prototype properties), however the function will not attempt to process a null
or an undefined
value and will just return it.
angular.forEach(object, function(value, key) { // function});
Examples:
angular.forEach({"a": 12, "b": 34}, (value, key) => console.log("key: " + key + ", value: " + value))
// key: a, value: 12
// key: b, value: 34
angular.forEach([2, 4, 6, 8, 10], (value, key) => console.log(key))
// will print the array indices: 1, 2, 3, 4, 5
angular.forEach([2, 4, 6, 8, 10], (value, key) => console.log(value))
// will print the array values: 2, 4, 6, 7, 10
angular.forEach(undefined, (value, key) => console.log("key: " + key + ", value: " + value))
// undefined