# Re: how to delete array

**URL:** <https://www.ruby-forum.com/t/re-how-to-delete-array/119585>\
**Category:** Ruby\
**Created:** [November 8, 2007, 6:28am UTC](https://www.ruby-forum.com/t/re-how-to-delete-array/119585 "2007-11-08T06:28:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [November 8, 2007, 6:28am UTC](https://www.ruby-forum.com/t/re-how-to-delete-array/119585/1 "2007-11-08T06:28:20Z")

</div>

ignore previous post (it does not work right)

maybe this one,

> array = [1,2,3,4,7,4]  
> =\> [1, 2, 3, 4, 7, 4]  
> del=[1,3]  
> =\> [1, 3]

> del.each{|i| array[i]=nil}  
> =\> [1, 3]  
> array.compact  
> =\> [1, 3, 7, 4]

# -----Original Message-----

# From: PeÃ±a, Botp

# Sent: Thursday, November 08, 2007 1:00 PM

# To: ‘removed\_email\_address@domain.invalid’

# Subject: RE: how to delete array

# 

# On Behalf Of Surjit N.

# # Array1 = [1,2,3,4,7,4]

# # indexes to be delted is collected in an array del=[1,3] …i.e

# # i should

# # delete 2 and 4 values

# # i tried using

# # Array1.delete\_at(del[])

# # but this doesn’t work

# 

# loop thru your indexes to the array, ie,

# 

# \> array = [1,2,3,4,7,4]

# =\> [1, 2, 3, 4, 7, 4]

# \> del=[1,3]

# =\> [1, 3]

# \> del.each{|i| array.delete\_at(i)}

# =\> [1, 3]

# \> array

# =\> [1, 3, 4, 4]

# 

# or you can then create your own fancy delete\_at method

# 

# \> class Array

# \> def delete\_atx(d)

# \> d.each{|i| self.delete\_at(i)}

# \> end

# \> end

# =\> nil

# \> array = [1,2,3,4,7,4]

# =\> [1, 2, 3, 4, 7, 4]

# \> del=[1,3]

# =\> [1, 3]

# \> array.delete\_atx del

# =\> [1, 3]

# \> array

# =\> [1, 3, 4, 4]

# 

# kind regards -botp

#
