Ruby for Instance / Arrays

# Define an array of numbers
numbers = [1, 2, 3, 4, 5]

# Define an array of strings
colors = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]

# Define an array of mixed data types
mixed = ["hello", 42, true, [1, 2, 3], :symbol]

# Define an empty array
empty = []

# Define an array with range syntax
range = (1..10).to_a

# Define an array with string elements
strings = %w(apple banana cherry)

# Define an array with the new keyword
arr = Array.new

Try on playground

Next: hash

made with by dfxe / source / license