Back to Course

Introduction to JavaScript

0% Complete
0/0 Steps
  1. JavaScript: Basics
    9Topics
    |
    10 Quizzes
  2. JavaScript: Variables
    9Topics
    |
    10 Quizzes
  3. JavaScript: Conditional Statements
    10Topics
    |
    11 Quizzes
  4. JavaScript: Functions
    10Topics
    |
    11 Quizzes
  5. JavaScript: Scope
    6Topics
    |
    7 Quizzes
  6. JavaScript: Arrays
    11Topics
    |
    12 Quizzes
  7. JavaScript: Loops
    8Topics
    |
    9 Quizzes
  8. JavaScript: High Order Functions
    3Topics
    |
    3 Quizzes
Lesson 6, Topic 8
In Progress

JavaScript: .pop() Method

Yasin Cakal 16 Nov 2021
Lesson Progress
0% Complete

.pop() is another array method that removes the last element from an array.

const evenNumbers = [2, 4, 6,8,10];
const removed = evenNumbers.pop();
console.log(evenNumbers); 
console.log(removed);

//Output: [ 2, 4, 6, 8 ]
//        10

In the above example, using .pop() on the evenNumbers array removed 10 from the end.

  • .pop() accepts no arguments and simply removes the last element of evenNumbers.
  • The value of the last element is returned by .pop(). In this example, we save the returned value in a variable removed that will be used later.
  • The method .pop() modifies the initial array by removing the last element of array.

Use .pop() to remove the last element from an array when you need to mutate it.

Responses

Leave a Reply

%d bloggers like this: