I have the following code in which I used local storage to store array of Product varient ID when user hits compre on every product description page.:
"Prdvar" contains product variants ID's (ex: 10,13, etc.,)
a.push(JSON.parse(localStorage.getItem('session')));
localStorage.setItem('session', JSON.stringify(a));
$scope.dataVarID = JSON.parse(localStorage.getItem('session'));
alert($scope.dataVarID); //Duplicate values present
$scope.CompareProduct = function() {
a = JSON.parse(localStorage.getItem('session'));
a.push("{ ProductVarient :"+Prdvar+"}");
alert(a);
localStorage.setItem('session', JSON.stringify(a));
};
My question is how to remove duplicate items present in $scope.dataVarID.
,{ ProductVarient :5},{ ProductVarient :5},{ ProductVarient :5},{ ProductVarient :33}
// I dontknow at first , is adding then 12,13,12,12
I need only ,{ ProductVarient :5},{ ProductVarient :33}
You can use map and filter out the duplicates