I am using below array for 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"
}
]
I need to get ids from the above array. I need to remove duplicate values before the push method.
this is my code
angular.forEach($scope.categoryList, function (object) {
$scope.myNewarray.push(object.id);
});
my new array data should be like as below
$scope.myNewarray = [44,76,77]
I need to get unique ids only for the my new array.
You can use Set to get the unique value from the array
$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",
},
];
$scope.myNewarray = [...new Set($scope.categoryList.map((o) => o.id))];