Delete The First Instance Of Value From Array In Ruby

Posted by Weston Ganger on January 07, 2016

I needed to remove the first occurrence of a value from my array.

my_array.delete_at(my_array.index(value_to_find) || my_array.length)

The my_array.length handles the case where the value is not in the array

Related External Links:

Posted in Rails and Tagged with ruby array 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts