This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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 upRelated 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