Taking into consideration that what you want to pass to your backend logic is an array.
This code is wrong
var selectedIds = angular.extend({}, $scope.selectedFirstKeys, $scope.selectedSecondKeys);
- Because: it copies the content of $scope.selectedFirstKeys,and$scope.selectedSecondKeysinto{}(which is an object!), so the final result will be an object too! :(
The correct way (Assuming that $scope.selectedSecondKeys and $scope.selectedSecondKeys are arrays) is:
$scope.selectedFirstKeys = $scope.selectedFirstKeys.concat($scope.selectedSecondKeys);
- Because: it set $scope.selectedFirstKeyswith the result of cancatenating$scope.selectedFirstKeysand$scope.selectedSecondKeys, which will be an array too! :)
You might want to see additional info about Array.prototype.concat (and on SO) and angular.extend (and on SO). An extract is shown below:
Array.prototype.concat
The concat() method returns a new array comprised of the array on
  which it is called joined with the array(s) and/or value(s) provided
  as arguments.
Syntax
var new_array = old_array.concat(value1[, value2[, ...[, valueN]]])
Parameters
valueN: Arrays and/or values to concatenate into a new array.
angular.extend
Extends the destination object dst by copying own enumerable
  properties from the src object(s) to dst.
Syntax
angular.extend(dst, src);
Parameters
dst: Destination object
src: Source object(s)