Nested foreach loop in Angular
15,438
This would be with angular :
angular.forEach(obj1, function(item1) {
angular.forEach(obj2, function(item2) {
if(item1.target_object_id===item2.id) {
item2.extra = item1.extra; // change it as you wish
// some code
}
});
});
Author by
Joyfulgrind
Updated on June 04, 2022Comments
-
Joyfulgrind almost 2 years
I have two arrays like this:
var obj1 = [{'target_object_id': 1, 'extra': 'ok'}, {'target_object_id': 2, 'extra': 'ok'}] var obj2 = [{'id': 4}, {'id': 2}]
What I want to do is loop through
obj1
andobj2
andif obj1.target_object_id == obj2.id // Append obj2['extra']=obj.extra
How to do this in angular?