I have a specific array that I am using in my foreach function
$scope.categoryList = [
{
"id": 44,
"creationTimestamp": "2019-11-15 17:11:17",
"name": "FIXED ",
"description": "FIXED",
"$$hashKey": "object:108"
},
{
"id": 44,
"creationTimestamp": "2019-11-15 17:09:32",
"name": "SAV",
"description": "SAV",
"$$hashKey": "object:109"
},
{
"id": 76,
"creationTimestamp": "2021-08-17 14:19:14",
"name": "TEST CAT",
"description": "TEST CAT",
"$$hashKey": "object:110"
},
{
"id": 77,
"creationTimestamp": "2021-08-17 14:19:14",
"name": "TEST CAT",
"description": "TEST CAT",
"$$hashKey": "object:110"
}
]
To extract the IDs from the array above and remove duplicate values before pushing them to a new array, I've written the following code:
angular.forEach($scope.categoryList, function (object) {
$scope.myNewarray.push(object.id);
});
The resulting new array should contain unique ID values like this:
$scope.myNewarray = [44,76,77]
I want only the unique IDs to be present in my new array.