Adding and Removing Elements From Arrays

Mostafa Said - Jan 20 '22 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player