How to add elements to end of array in Ruby

2 Answers

0 votes
arr = ["ruby", "c++", "go", "php", "java"]

arr.push("c")
arr.push("c#")

print arr



# run:

# ["ruby", "c++", "go", "php", "java", "c", "c#"]

 



answered Aug 30, 2020 by avibootz
0 votes
arr = Array[]

arr.push("c")
arr.push("c#")
arr.push("ruby")

print arr



# run:

# ["c", "c#", "ruby"]

 



answered Aug 30, 2020 by avibootz

Related questions

1 answer 235 views
1 answer 194 views
1 answer 221 views
1 answer 225 views
1 answer 154 views
154 views asked Oct 17, 2022 by avibootz
1 answer 186 views
...