I have JSON object like below
{ "txt_inc_Application": { "EWS": true, "EWindow": true }, "txt_inc_IncidentType": { "Brand Damage": true, "Internal failure": true } }
And I am using angular.forEach to get the values
$scope.filterFormula=function() { angular.forEach($scope.filters, function(filterObj , filterIndex) { angular.forEach(filterObj, function(value , key) { console.log(value+"--"+key) }) }) }
How can i get "txt_inc_Application" and "txt_inc_IncidentType" in the loop?
Also when call the angular function in html like below why it is getting executed twice?
{{filterFormula()}}
Overview. Extends the destination object dst by copying own enumerable properties from the src object(s) to dst . You can specify multiple src objects. If you want to preserve original objects, you can do so by passing an empty object as the target: var object = angular. extend({}, object1, object2) .
You can loop through an Array or an Object in AngularJS using the forEach() function. The function invokes the iterator function that iterates or loops through each item in an array.
forEach() Function in AngularJS is used to iterate through each item in an array or object. It works similar to the for loop and this loop contains all properties of an object in key-value pairs of an object. Parameter Values: object: It refers to the object to be iterated.
The first parameter to the iterator in forEach
is the value and second is the key of the object.
angular.forEach(objectToIterate, function(value, key) { /* do something for all key: value pairs */ });
In your example, the outer forEach is actually:
angular.forEach($scope.filters, function(filterObj , filterKey)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With