This because array is passed along as reference which means even if you reassign it, there is only one array in the memory and all of your assignments points to a single thing. Try making a deep copy of the object, this will create a new array and no longer modify the same old array.