JavaScript .pop()

codewithfan's avatar
Published Jun 18, 2021Updated Jun 1, 2023
Contribute to Docs

Removes the last element of an array, decrements the array length, and returns the value that it removed.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

array.pop();

Example

To pop the element 'sleep' from the schedule array:

const schedule = ['wake up', 'eat', 'work', 'play', 'sleep'];
const lastThingToDo = schedule.pop();
console.log(lastThingToDo);
console.log(schedule);

This results in the following output:

sleep
['wake up', 'eat', 'work', 'play']

Codebyte Example

The following example below uses .pop() on an array, flavor, to remove the last element.

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours