Join my Laravel for REST API's course on Udemy 👀

Join an array of strings by a comma in Ruby

August 10, 2022  ‐ 1 min read

To join an array to a string we can use the Ruby .join() method. This method takes as its argument the separator character to place between the elements in the array. Thus, to join array elements by a comma we can pass ", " as an argument to .join().

['a', 'b', 'c'].join(', ')
# => "a, b, c"