Start learning free

LESSON 115 OF 679 · ARRAYS I

Remove Last Item From Vector in Rust

Lesson

Another way to change the data in a vector is with the .pop() method, which removes the last element from a vector:

let mut three_arr = vec![1, 4, 6];

// Remove last element:
three_arr.pop();

// three_arr is now vec![1, 4]

// Remove last element again:
three_arr.pop();

// three_arr is now vec![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