utulity function to remove old elements from an array