Start learning free

LESSON 113 OF 675 · ARRAYS I

Remove Last Item From Array in TypeScript

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:
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