Start learning free

LESSON 102 OF 348 · ARRAYS I

Remove Last Item From Vector in Rust 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

    Array Pop in Rust

    Keep going with RustAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free