DEV Community

Cover image for Adding and Removing Elements From Arrays
Mostafa Said
Mostafa Said

Posted on

1 1

Adding and Removing Elements From Arrays

Hello everyone,

Adding and removing elements from arrays is a must have skill in programming. It's one of the most basic things you learn in any language but it's the most essential as well. Without too much talking, let's dig in:

1- Adding Elements to Array.

push:

  • Add an element to the end of an array.

unshift:

  • Add an element to the beginning of an array.

splice:

  • Add an element to the middle of an array.

Full explanation with example below πŸ‘‡

Push - unshift - splice.png

2- Removing Elements to Array.

pop:

  • Remove the last element of an array.

Removing last element pop.png

shift:

  • Remove the first element of an array.

splice:

  • Remove elements from the middle of an array.

Removing elements from array.png

Support me:

  • Leave a reaction if you're happy with the article.
  • Leave a comment if you have a constructive feedback or hate that I explained the logic in pictures.

Thanks for reading.

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs