I am facing some issue while returning value from angular forEach.
Here is my data:
vm.memberDetails={ "member": [ { "firstName": "HARRY UTTWO", "lastName": "POTTER", } ], "User": [ { "memberId": 7586671, "customerId": 7586671, "customerStatus": "T", "firstName": "HEMOOINE", "lastName": "POTTER", }, ] }vm.mockData = {
“data”: [{
“memberNo”: 7586671,
“suffix”: “A”
}]
}
Here I need to compare memberId and get name from first data.I used angular.forEach but for name i need to use
vm.memberDetails.User[0].firstName
but it return only on value with looping.
Controller:
angular.forEach(vm.memberDetails.User, function (value1,key1) {
angular.forEach(vm.mockData, function (value2,key2) {
if (value1.memberId === value2.memberNo) {vm.some= vm.memberDetails.User[0].firstName; } });
});
return vm.some;
Any help would be appreciated. Thanks.
#javascript #angular.js