Having two sets of JSON data:
vm.userListData = [{
"listId": 1,
"permission": "READ"
}, {
"listId": 2,
"permission": "WRITE"
}, {
"listId": 2,
"permission": "READ"
}, {
"listId": 3,
"permission": "READ"
}, {
"listId": 3,
"permission": "WRITE"
}, {
"listId": 4,
"permission": "WRITE"
}, {
"listId": 5,
"permission": "WRITE"
}]
vm.userComplementaryList = [{
"listId": 1,
"confidentiality": "PUBLIC",
"listName": "List name here..1",
"permission": "WRITE"
}, {
"listId": 2,
"confidentiality": "PUBLIC",
"listName": "List name here..2",
"permission": "READ"
}, {
"listId": 3,
"confidentiality": "CONFIDENTIAL",
"listName": "List name here..3",
"permission": "WRITE"
}, {
"listId": 4,
"confidentiality": "CONFIDENTIAL",
"listName": "List name here..4",
"permission": "WRITE"
}, {
"listId": 5,
"confidentiality": "CONFIDENTIAL",
"listName": "List name here..5",
"permission": "READ"
}]
I am filtering and pushing unique values into one array, and duplicated values into another. Here's my code:
vm.listForGrid = [];
vm.listForDropDown = [];
(function(){
for(var i = 0; i < vm.userComplementaryList.length; i++) {
for(var j = 0; j < vm.userListData.length; j++) {
if( (vm.userComplementaryList[i].listId == vm.userListData[j].listId) && (vm.userComplementaryList[i].permission == vm.userListData[j].permission) ) {
vm.listForGrid.push(vm.userComplementaryList[i]);
}
else {
vm.listForDropDown.push(vm.userComplementaryList[i]);
}
}
}
})();
The vm.listForGrid
has the correct values, but I'm facing duplications in vm.listForDropDown
. I need to implement a break
statement to resolve this issue.
Please note that the duplicates occur when the listId and permission are the same in both arrays.
Thank you!