mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
array first and last methods
This commit is contained in:
parent
e3c528bb81
commit
f4c13bc696
@ -155,6 +155,7 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
|
||||
# Arrays can be indexed
|
||||
# From the front
|
||||
array[0] #=> 1
|
||||
array.first #=> 1
|
||||
array[12] #=> nil
|
||||
|
||||
# Like arithmetic, [var] access
|
||||
@ -165,6 +166,7 @@ array.[] 12 #=> nil
|
||||
|
||||
# From the end
|
||||
array[-1] #=> 5
|
||||
array.last #=> 5
|
||||
|
||||
# With a start index and length
|
||||
array[2, 3] #=> [3, 4, 5]
|
||||
|
Loading…
Reference in New Issue
Block a user