LESSON 38 OF 50

Remove the last element with pop

Remove and keep the last array value.

Official sourceECMAScript — Array.prototype.popReviewed: 2026-08-26
STEP 1 · LEARN

How it works

pop removes the last element and returns it. If the array is empty, the result is undefined.

Correct example
const services = ['Design', 'Dezvoltare', 'SEO'];
const removed = services.pop();
console.log(removed);
console.log(services.length);

SEO is returned into removed, and the array keeps two elements.

Common mistake
const removed = 'SEO';
console.log(removed);
console.log(2);

The output is imitated, but the array is not changed through pop.

STEP 2 · APPLY

Your exercise

Store services.pop() in removed, then print removed and services.length.

STEP 3 · RUN

Write and run the code

script.jsJAVASCRIPT
Isolated consoleisolated
Preparing the runtime…
Run the code to see the result.
The draft stays only in this browser.Isolated QuickJS · no DOM, session or network
STEP 4 · CHECK

What needs to pass

0%not checked
  • services starts with three elements.
  • removed receives the result of services.pop().
  • The output is SEO, then 2.
Explain the solution logic

The method returns the removed value and updates the same collection length.