method
last
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
last(*args)
public
Register or
log in
to add new notes.
tadman -
April 16, 2009
autonomous -
August 18, 2008
![Default_avatar_30](https://www.gravatar.com/avatar/b850a6cd0c0f8993fa152645ca9a7fbd?default=http://apidock.com/images/default_avatar_30.png&size=30)
1 thank
Extracting the Last Element
To remove the last element from the Array, use pop:
array = [ 1, 2, 3 ] # => [ 1, 2, 3 ] array.last # => 3 array # => [ 1, 2, 3 ] array.pop # => 3 array # => [ 1, 2 ]
![Default_avatar_30](https://www.gravatar.com/avatar/57e3855c26bec5183a6d8369d7122709?default=http://apidock.com/images/default_avatar_30.png&size=30)
0 thanks
Last element of an array alternative
You can also access the last element of an array with -1
[ "w", "x", "y", "z" ][-1] #=> "z"