Skip to content
Advertisements

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
Advertisements

2 Comments »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

%d bloggers like this: