Seeking advice from a novice.
I am working on a project where I need to create a list with a Key/Value structure. I have assigned the Id as the Key and the rest of the information as the value, so as I add more records, they get appended to my list $scope.itemList[]
var data = [
{
id: 1,
name : "Peter",
lastname : "Smith",
age : 36
}, {
id: 2,
name : "Peter",
lastname : "Smith",
age : 36
}
];
$scope.itemList = [];
angular.forEach(data, function(item){
var obj = {};
var valObj = {};
valObj.name = item.name;
valObj.lastname = item.lastname;
valObj.age = item.age;
obj[item.id] = valObj;
$scope.itemList.push(obj);
});
The challenge I am facing is handling duplicate records in the JSON file. The current code does not check for duplicate ids while pushing items to the list. I have tried various methods to compare the object with the item's id but none seem to be working.
I would greatly appreciate any assistance or guidance on how to address this issue.