Skip to main content

Array Operations: Modify Arrays

Arrays can be modified. Add elements. Remove elements. Change them.

Here's the thing: Array operations let you modify arrays. Learn them. Use them.

Adding Elements

fruits=("apple" "banana")
fruits+=("orange")

My take: += adds elements. Simple.

Removing Elements

fruits=("apple" "banana" "orange")
unset fruits[1] # Remove banana

My take: unset removes elements. Use it.

Modifying Elements

fruits=("apple" "banana")
fruits[0]="grape"

My take: Modify by index. Simple.

Common Patterns

Add Multiple

items=("one")
items+=("two" "three")

What's Next?

Now that you understand operations, let's talk about Associative Arrays.


Personal note: Array operations seemed complex. Then I learned them. Now I use them. They're useful. Learn them.