Skip to content
instance method

Array#delete_at

(::int index) -> Elem
delete_at(index) → removed_object or nil

Removes the element of self at the given index, which must be an integer-convertible object.

When index is non-negative, deletes the element at offset index:

Example
a = [:foo, 'bar', 2]
a.delete_at(1) # => "bar"
a # => [:foo, 2]

When index is negative, counts backward from the end of the array:

Example
a = [:foo, 'bar', 2]
a.delete_at(-2) # => "bar"
a # => [:foo, 2]

When index is out of range, returns nil.

Example
a = [:foo, 'bar', 2]
a.delete_at(3)  # => nil
a.delete_at(-4) # => nil

Related: see Methods for Deleting.

See also #delete #delete_if #cycle #detect also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0