Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Remove array elements in Ruby

  • Last Updated : 20 Jul, 2021

In this article, we will learn how to remove elements from an array in Ruby.

Method #1: Using Index

Ruby




# Ruby program to remove elements 
# in array
   
# creating string using []
str = ["GFG", "G4G", "Sudo", "Geeks"]
   
str.delete_at(0)
print str

Output:

["G4G", "Sudo", "Geeks"

Method #2: Using delete() method –

Ruby




# Ruby program to remove elements 
# in array
   
# creating string using []
str = ["GFG", "G4G", "Sudo", "Geeks"]
   
str.delete("Sudo")
print str

Output:



 ["GFG", "G4G", "Geeks"

Method #3: Using pop() method –

Ruby




# Ruby program to remove elements 
# in array
   
# creating string using []
str = ["GFG", "G4G", "Sudo", "Geeks"]
   
str.pop
print str

Output:

 ["GFG", "G4G", "Sudo"] 

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!