Array pop()

JavaScript Array pop() Definition

The pop () method removes the last element of an array. And define a new array. So this method changes the sequence (length and elements).
pop () does not perform properly when applied regularly to non-sequence arrays. If we apply pop () in an empty array, it returns the “undefined” value.

Syntax:

array.pop()


JavaScript Array pop() Examples

Example 1

        let animal = ["cat", "dog", "horse", "donkey"];
        console.log(animal.pop())

output:

donkey


Example 2

        let numbers = ["first", "second", "third"];

        let third = numbers.pop();
        console.log(third)

        let second = numbers.pop();
        console.log(second)

        let first = numbers.pop();
        console.log(first)

output:

third
second
first


Example 3

        let alphabet = ["a", "b", "c", "d"];

        var newList = alphabet.pop();

        console.log(alphabet);
        console.log(newList);

output:

[“a”, “b”, “c”]
d


Browser Support

Chrome1
Edgeyes
Firefox1
Internet Explorer5.5
Operayes
Safariyes
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android4
Opera Androidyes

2 thoughts on “Array pop()

Add yours

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started