in reply to pop and shift not reversible

The solutions Re: pop and shift not reversible proposed by hippo and Re: pop and shift not reversible ( while @array ) proposed by Anonymous Monk are not the same if the data array contains undefined elements. The later probably better answers the question in your title because it does not depend on the contents of the array, only its size. On the other hand, the former is often preferred precisely because it does not return undefined data at the end of the array.
Bill