Start learning free

LESSON 110 OF 671 · ARRAYS I

Remove Last Item From Array in JavaScript

Lesson

Another way to change the data in an array is with the .pop() method.

.pop() removes the last element of an array and also returns the value of that element:

let threeArr = [1, 4, 6];

// Remove last element:
let oneDown = threeArr.pop();

console.log(oneDown); // Output: 6
console.log(threeArr); // Output: [1, 4]

// Remove last element again:
let oneDown = threeArr.pop();

console.log(oneDown); // Output: 4
console.log(threeArr); // Output: [1]

Assignment
Follow the Coding Tutorial and let's play with some arrays.


Hint
Look at the examples above if you get stuck.


STEP 1 OF 2
    Ctrl + Enter to check