ruby get the first element of an array
array = [1, 2, 3]
array.first
=> 1
ruby get the first element of an array
array = [1, 2, 3]
array.first
=> 1
ruby .first
# Returns the first element, or the first n elements, of the array.
# If the array is empty, the first form returns nil,
# and the second form returns an empty array.
a = [ "q", "r", "s", "t" ]
a.first #=> "q"
a.first(2) #=> ["q", "r"]
[46] pry(main)> a = []
=> []
[47] pry(main)> a.first
=> nil
[48] pry(main)> a.first(2)
=> []
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us