Removing objects from array in reverse order

I have a selection mechanic that will select objects underneath a drag gesture.
I’m trying to deselect the objects when retracing the gesture backwards… the code bellow works for deselecting objects when going over them again, but i want to limit it to the order the objects are in the array. Essentially so objects can only be deselected in the reverse order they were selected in, including the last. if that makes sense.

else if(hit.transform.GetComponent("ObjectSelected").isSelected == true && dragging)
	{
		for(var zz : int = selected.length-1; zz >= 0; zz--){
				
				zz -= 1;
				if(selected[zz] == hit.transform)
				{
				selected.RemoveAt(zz);
				hit.transform.GetComponent("ObjectSelected").Selected(false);
				//Debug.Log("Selected object index length= " + selected.length);
				
				//selected.RemoveAt(selected.length-1);
				//selected[selected.length-1].transform.GetComponent("ObjectSelected").Selected(false);
				break;
				}
				
			}

Editing: I just noticed that you are using RemoveAt, which means the array is a JS array.

Just use Pop():

LastItem = Array.Pop()

This would remove the last entry from the array and assign it to LastItem.

Shift() would remove from the beginning.