OneBite.Dev - Coding blog in a bite size

append item in array in Ruby

Code snippet on how to append item in array in Ruby

fruits = ["apple", "banana", "grape"]

# append orange to the end of the fruits array

fruits << "orange"
``

This Ruby code adds the string "orange" to the end of the fruits array, which is initially declared as ["apple", "banana", "grape"]. The << (append) operator adds the item to the end of the array. In this example, the new array would be ["apple", "banana", "grape", "orange"].
ruby