From: Tim Hunter Date: 2007-11-08T05:28:30+09:00 Subject: Re: how to delete array Jeremy Woertink wrote: > Surjit Nameirakpam wrote: >> Problem >> >> consider an array >> >> a = [1,4,6,7,9,8] >> >> I want to delete the array value w.r.t index >> >> e.g i want to delte 0,4,6 element in one go >> >> I can use the command >> a.delete_at(0) >> a.delete_at(4) >> a.delete_at(6) >> >> But the problem is that i dont know how much element will be populated >> in my array every time the program runs and the index value will also >> change. >> >> So i need to dynamically pass the index value and this should delete the >> values pertaining to the index > > you could try something like... > > a.each_with_index do |item, index| > a.delete_at(index) if item.eql?(something) > end > > > ~Jeremy I think you want Array#delete_if. a.delete_if {|v| v == 1} deletes all entries in a that are 1. -- Posted via http://www.ruby-forum.com/.