Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Arrays intro

  • [Array API](https://crystal-lang.org/api/Array.html" %}
  • [Array reference](https://crystal-lang.org/reference/syntax_and_semantics/literals/array.html" %}
planets = ["Mars", "Jupyter", "Saturn", "Earth"]
p! planets           # ["Mars", "Jupyter", "Saturn", "Earth"]
puts typeof(planets) # Array(String)
puts planets.size    # 4

integers = [3, 8, -2]
puts typeof(integers) # Array(Int32)

floats = [3.14, 2.1]
puts typeof(floats) # Array(Float64)

mixed = [1, 3.14, "PI"]
puts typeof(mixed) # Array(Float64 | Int32 | String)