How can I merge matching objects from 2 array objects in Angular JS?
Array 1:
[
{"id":1,"name":"Adam"},
{"id":2,"name":"Smith"},
{"id":3,"name":"Eve"},
{"id":4,"name":"Gary"},
]
Array 2:
[
{"id":1,"name":"Adam", "checked":true},
{"id":3,"name":"Eve", "checked":true},
]
Desired Resulting Array:
[
{"id":1,"name":"Adam", "checked":true},
{"id":2,"name":"Smith"},
{"id":3,"name":"Eve", "checked":true},
{"id":4,"name":"Gary"},
]
Is there a way to achieve this without a foreach
loop?
I've attempted to use angular.merge
and angular.extend
but they overlap the first 2 objects instead of merging them based on matching data. Any guidance would be appreciated.