Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
An array is a container of data, similar to a list. In this video, we'll learn what arrays are and how to create them.
Code Samples
Create an array:
array = Array.new
Create an array with three items:
array = Array.new(3, "Jason")
Create an empty array with bracket notation:
array = []
Create an array using brackets with three items:
array = ["milk", "eggs", "bread"]
Create an array using the %w
notation which contains three strings:
array = %w(milk eggs bread)
Create an array using the %W
notation which contains three strings and one is interpolated:
item = “milk”
array = %W(#{item} eggs bread)
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
christian rylander
4,609 Points1 Answer
-
Joy McCaffrey
3,333 Points1 Answer
-
A X
12,842 Points1 Answer
-
Anna Liewald
3,447 Points10 Answers
-
Sven Vanlandschoot
11,252 Points2 Answers
-
Ryan Egan
5,324 Points1 Answer
-
Jennifer Krohn
1,661 Points3 Answers
-
Alexei Parphyonov
34,128 Points2 Answers
-
MICHAEL P
5,191 PointsWhat is the keyboard shortcut that Jason uses to quickly "recall" the array in irb?
Posted by MICHAEL PMICHAEL P
5,191 Points4 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up