0

I have 2 arrays

 $scope.allnamesList =[];
 $scope.namesList = result.data.namesfields;   

The problem is that i cant clear the allnamesList because i want to preserve values on client side.

I have tried $scope.allnamesList.push.apply($scope.allnamesList, $scope.namesList), but the issue is that it keeps adding even if the values returned from MVC in the result.data.namesfields are already present in $scope.allnamesList.

Is it possible to do a push of elements in nameslist if they dont already exist in allnamesList ?

Georgia
  • 27
  • 5
  • you can use a set to avoid duplicates if the individual elements in the names list are just strings – cmgchess Jul 12 '22 at 10:26
  • Use a [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instead of an array – adiga Jul 12 '22 at 10:29
  • the list is a list of objects. Also Set can't be implicitly converted to an array type? – Georgia Jul 12 '22 at 10:31
  • maybe this will help https://stackoverflow.com/questions/2218999/how-to-remove-all-duplicates-from-an-array-of-objects – cmgchess Jul 12 '22 at 10:32
  • The issue here is that it is a list of objects and one property is boolean and the list is bound to a grid which governs if a checkbox is selected or not . If i use the suggested link the state of the check box is not saved . When it filters it seems to filter even if i check for the stae of the checkbox – Georgia Jul 12 '22 at 10:44

0 Answers0