Javascript Array pop

Javascript Array pop Method

At times, we might require to remove the last element from the array. In such situations, we directly have the pop method, which helps us remove the last element from the array, and returns the removed element as well.

We are now going to have a look at an example, through which, we get a clearer idea of what is going on. Just remember that we have an array, and we have inserted some elements into it, and now we want to remove the last element from the array, and in such situations, the pop method is going to help.

Javascript Array pop Method

Below is the program which demonstrates the pop method –

As you can see in the above program, we have an array with some elements, and we have called the pop method. So, the pop method removes the last element from the array and returns it.

Now, let’s have a look at the output →

As you can see, the value true was popped from the array, since it was the last one, and the pop method has returned that value, which is being shown in the output. You can also try using the pop method for practice, and we can use it as and when required.