OneBite.Dev - Coding blog in a bite size

find the length of an array in Ruby

Code snippet on how to find the length of an array in Ruby

  arr = [1, 2, 3, 4, 5]
  arr.length

This code finds the length of the array “arr”. The first line creates an array called arr and assigns it the values 1, 2, 3, 4, and 5. The second line uses the .length method to find the length of arr and returns the value 5, which is the number of elements in the array.

ruby