Using shift and unshift : shift « Array « Ruby






Using shift and unshift


# To remove an element from an array is with the shift method. 
# This method returns the first element of an array (nil if the array is empty), and then removes the element, shifting all other elements down by one. 

dates = [ 4, 5, 6, 7 ] # => [4, 5, 6, 7]
dates.shift # => 4
p dates # => [5, 6, 7]

 








Related examples in the same category