• Skip to main content
  • Skip to search
  • Skip to select language
HTML

Structure of content on the web

  • Web APIs

    Interfaces for building web applications

  • Learn
    • CSS

      Learn to style content using CSS

    • Overview

      A customized MDN experience

    • FAQ

      Frequently asked questions about MDN Plus

  • HTTP Observatory

    Scan a website for free

  • JavaScript
  • Array.prototype.pop()
      • Deutsch
      • Español
      • Français
      • 日本語
      • 한국어
      • Português (do Brasil)
      • Русский
      • 中文 (简体)
      • 正體中文 (繁體)

    In this article

    • Try it
    • Syntax
    • Description
    • Examples
    • Specifications
    • Browser compatibility
    • See also
    1. Array.from()
    2. Array[Symbol.species]
  • Instance methods
    1. Array.prototype.entries()
    2. Array.prototype.find()
    3. Array.prototype.flat()
    4. Array.prototype.indexOf()
    5. Array.prototype.map()
    6. Array.prototype.reduceRight()
    7. Array.prototype.some()
    8. Array.prototype.toReversed()
    9. Array.prototype.unshift()
    10. Array: length
    11. Function.prototype.bind()
    12. Function: displayName Non-standard
    13. Function.prototype.arguments Non-standard Deprecated
    14. Function.prototype.caller Non-standard Deprecated
  • Instance methods
    1. Object.prototype.__defineGetter__() Deprecated
    2. Object.prototype.__defineSetter__() Deprecated
    3. Object.prototype.__lookupGetter__() Deprecated
    4. Object.prototype.__lookupSetter__() Deprecated
    5. Object.prototype.toLocaleString()
    6. Object.prototype.__proto__ Deprecated
    7. Array instances removes the last element from an array and returns that element. This method changes the length of the array.

  • Try it

    const plants = ["broccoli", "cauliflower", "cabbage", "kale", "tomato"];
    
    console.log(plants.pop());
    / Expected output: "tomato"
    
    console.log(plants);
    / Expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]
    
    plants.pop();
    
    console.log(plants);
    / Expected output: Array ["broccoli", "cauliflower", "cabbage"]
    

    Syntax

    js
    pop()
    

    Parameters

    None.

    Return value

    The removed element from the array; undefined.

    Array.prototype.shift() has similar behavior to pop(), but applied to the first element in an array.

    The pop() method is a mutating method. It changes the length and the content of this. In case you want the value of this to be the same, but return a new array with the last element removed, you can use arr.slice(0, -1) instead.

    The pop() method is generic. It only expects the this value to have a length property and integer-keyed properties. Although strings are also array-like, this method is not suitable to be applied on them, as strings are immutable.

    Examples

    Removing the last element of an array

    The following code creates the myFish array containing four elements, then removes its last element.

    js
    const myFish = ["angel", "clown", "mandarin", "sturgeon"];
    
    const popped = myFish.pop();
    
    console.log(myFish); / ['angel', 'clown', 'mandarin' ]
    
    console.log(popped); / 'sturgeon'
    

    Calling pop() on non-array objects

    The pop() method reads the length property of this. If the deleted.

    js
    const arrayLike = {
      length: 3,
      unrelated: "foo",
      2: 4,
    };
    console.log(Array.prototype.pop.call(arrayLike));
    / 4
    console.log(arrayLike);
    / { length: 2, unrelated: 'foo' }
    
    const plainObj = {};
    / There's no length property, so the length is 0
    Array.prototype.pop.call(plainObj);
    console.log(plainObj);
    / { length: 0 }
    

    Using an object in an array-like fashion

    push and pop are intentionally generic, and we can use that to our advantage — as the following example shows.

    Note that in this example, we don't create an array to store a collection of objects. Instead, we store the collection on the object itself and use call on Array.prototype.push and Array.prototype.pop to trick those methods into thinking we're dealing with an array.

    js
    const collection = {
      length: 0,
      addElements(...elements) {
        / obj.length will be incremented automatically
        / every time an element is added.
    
        / Returning what push returns; that is
        / the new value of length property.
        return [].push.call(this, ...elements);
      },
      removeElement() {
        / obj.length will be decremented automatically
        / every time an element is removed.
    
        / Returning what pop returns; that is
        / the removed element.
        return [].pop.call(this);
      },
    };
    
    collection.addElements(10, 20, 30);
    console.log(collection.length); / 3
    collection.removeElement();
    console.log(collection.length); / 2
    

    Specifications

    Specification
    ECMAScript® 2026 Language Specification
    # sec-array.prototype.pop

    Browser compatibility

    See also

    • Indexed collections guide
    • Array
    • Array.prototype.push()
    • Array.prototype.shift()
    • Array.prototype.unshift()
    • Array.prototype.concat()
    • Array.prototype.splice()

    Help improve MDN

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant