Subscribe to get my new tutorials in your inbox.
array pop in javascript

JavaScript Array Pop – Removing items from an array

An array, as you might know, is a data structure to hold and manage data. Like other programming languages, even JavaScript has built-in support for arrays. Let’s see how to do an Array pop in JavaScript,

Define an array in JS

var arr = [1,2,3,4,5];

In JavaScript arrays are dynamic, in fact, JS is a dynamic language. You can add or remove items to an array at any time in your program.

Adding item to an array,

//different ways to add items
arr = [...arr, 7,8];

You can also check out this post which talks about the various ways of adding items, multiple items to an array.

To remove items from an array we use the pop() method. It is also called an array pop.

var arr = ["a", "b", "c", "d"];
arr.pop(); //returns "d"

Pop removes an item from the end of the array.

Visualize it like a Stack. Popping out always happens from the top of the stack i.e the end of the array.

Write a Comment

Your email address will not be published. Required fields are marked *