Created
June 10, 2020 20:56
-
-
Save iJKTen/526c5b36248c2bf1ff42c5d8b64f0821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [] | |
// Another way to declare an array | |
arr = Array.new | |
arr.push(1) | |
# append is an alias for push | |
arr.append(2) | |
arr.insert(2, 3) | |
# we can pass multiple items to the array | |
arr.push(4, 5, 6, 7, 8) | |
arr[0] | |
arr[1] | |
arr[2] | |
arr[3] | |
arr[4] | |
arr[5] | |
arr[6] | |
arr[7] | |
for item in arr do | |
puts item | |
end | |
arr.each_with_index do |item, index| | |
puts index, item | |
end | |
arr.each {|item| | |
puts item | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment