It's because the array dupeArray
is just a reference to the original array theCardArray
, so when you clear the original array you are also clearing the duplicate array; by reference.
In order to resolve your issue you should clone the original array, this can be done using slice like this...
var dupeArray = theCardArray.slice(0);
Alternatively, it can also be done using the jQuery extend approach like this...
var dupeArray = $.extend(true, [], theCardArray);