3

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 and obj2 and

if obj1.target_object_id == obj2.id // Append obj2['extra']=obj.extra

How to do this in angular?

1 Answer 1

8

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
     }
   });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.