Array#append

arr.append(*objects) -> arr
Returns: Array · Updated March 13, 2026 · Array Methods
arrays mutation elements

Array#append adds one or more elements to the end of an array, mutating it in place. It returns the same array object, allowing method chaining.

Syntax

array.append(*objects)

Parameters

ParameterTypeDefaultDescription
*objectsObjectRequiredOne or more objects to add to the array

Examples

Basic usage

fruits = ["apple", "banana"]

fruits.append("cherry")
fruits
# => ["apple", "banana", "cherry"]

Adding multiple elements

numbers = [1, 2, 3]
numbers.append(4, 5, 6)
numbers
# => [1, 2, 3, 4, 5, 6]

Method chaining

result = [].append(1).append(2)
result
# => [1, 2]

Common Patterns

Building an array incrementally

items = []
items.append("first")
items.append("second")
items.append("third")
# => ["first", "second", "third"]

Stack-like behavior with append

stack = []
stack.append("first")
stack.append("second")
stack.pop  # => "second"

Edge Cases

Adding nil or false

arr = [1, 2]
arr.append(nil)
arr.append(false)
arr
# => [1, 2, nil, false]

Adding to empty array

arr = []
arr.append("first")
arr
# => ["first"]

Adding mixed types

mixed = []
mixed.append(1, "two", :three, [4, 5], {six: 6})
mixed
# => [1, "two", :three, [4, 5], {:six=>6}]

Performance Notes

append mutates the array in place, which is more memory-efficient than creating new arrays with + or concatenation. It runs in amortized O(1) time.

See Also