Initializing Arrays
Learn how to initialize arrays in Ruby.
We'll cover the following...
In this lesson, we’ll learn how to initialize a simple, one-dimensional array. There could be arrays with multiple dimensions, but for beginner programmers, two dimensions are usually enough. We will make sure to practice initializing, accessing, and iterating over 1D and 2D arrays, because it’s a very common pitfall during interviews. Sometimes, initializing arrays correctly is winning half the battle.
We are already familiar with the following syntax, which creates an empty array:
arr = []
Array with predefined values
If we want to initialize an array with predefined ...