OneBite.Dev - Coding blog in a bite size

create an array of number in Ruby

Code snippet on how to create an array of number in Ruby

  array_numbers = [1, 2, 3, 4, 5]

This code creates an array of numbers in Ruby. An array is a ordered list of objects such as numbers, strings, or any other kind of data. To create an array you need to use brackets, [], and then list the elements of the array. In this example, we are creating an array with the numbers 1, 2, 3, 4, and 5. The elements in the array are separated by commas and each element will be ordered according to the way they were placed. Once the array is created, it can be accessed by referencing the array name followed by an index number - for instance, array_numbers[0] will access the first element, which is 1.

ruby