Use square brackets () to build an array in a Ruby programme, and commas to separate the values you want to store.
Array#length(): length() is a method of the Array class that returns the number of elements in the array. The number of elements in the array is returned.
The simplest approach to print the contents of an array is to pass the array as a parameter to the puts or print method. On a separate line, each element is printed. The output is more readable when the examine method is used. The line outputs the array's string representation to the terminal.
Because the index of each item in an array maps to a specific memory address, which may be accessed directly without traversing the array, arrays allow for random access. Arrays just need to contain data, hence pointers to other memory addresses are unnecessary.
Array#unshift prepends an element to the beginning of an array, while Array#push appends an element to the end of an array in Ruby. The names of these approaches aren't immediately obvious. Prepend and append are aliases for the unshift and push methods in Active Support from Rails.