← ACARA Digital Technologies Years 9–10

Removing items with pop, shift and splice

Array methods that remove items and change the original array: pop removes the last item, shift removes the first, splice(index, count) removes count items starting at index.

Understanding Removing items with pop, shift and splice in ACARA Digital Technologies Years 9–10

What it does: splice(index, count) starts at index 1 and removes 2 items, changing the original array. pop() returns the removed item, so it can be stored in a variable while the array loses its last item. shift() removes the FIRST item, so 1 is removed and a becomes [2, 3]. shift() removes from the start of the array. pop() removes from the end.

Common mistakes: pop is a method, so it needs parentheses to run. Without them the line does nothing and no item is removed. It should be stack.pop();. length is a property, not a method, so it has no parentheses. It should be line.length. After shift and pop, 2 items remain.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 710–727) and word search (Modules 710–742).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
let a = [1, 2, 3]; a.pop(); What is a now?
[2, 3][1, 2]
Matches
fruits.pop(0);
↓
pop() always removes the last item and does not take an index. To remove the first item use fruits.shift() instead.
Applying
Meanings
Term
pop(), shift(), splice()
Meaning
Array methods that remove items and change the original array: pop removes the last item, shift removes the first, splice(index, count) removes count items starting at index.
Practice
let queue = ['Ava', 'Liam', 'Mia', 'Noah', 'Zoe'];
Testing
Gaps
songs.();
Check Answer
Spots
2stack.push(8);
3stack.pop;

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Cosmic Dragon' badge — Orbit Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. let a = [1, 2, 3]; a.pop(); What is a now?
A. [1, 2] ✓
B. [2, 3]
pop() removes the LAST item, so 3 is removed and a becomes [1, 2].
2. let a = [1, 2, 3]; a.shift(); What is a now?
A. [2, 3] ✓
B. [1, 2]
shift() removes the FIRST item, so 1 is removed and a becomes [2, 3].
3. Which call removes 2 items starting at index 1?
A. arr.splice(1, 2) ✓
B. arr.splice(2, 1)
splice(index, count) takes the start index first, then how many items to remove.
4. Do pop, shift and splice change the original array?
A. No, they return a new array and leave the original alone
B. Yes, they change the original array ✓
These are mutating methods. The original array is changed, so the removed items are gone from it.
5. let names = ['Ava', 'Liam', 'Mia']; let x = names.pop(); What is x?
A. 'Ava'
B. 'Mia' ✓
pop() returns the item it removed. The last item is 'Mia'.

Match the Pairs

playlist.pop() → Removes the last song from the playlist array and returns it
queue.shift() → Removes the first person from the queue array and returns them
Remove 2 items from the scores array, starting at index 1 → scores.splice(1, 2)
Remove the last item and save it in a variable called lastItem → let lastItem = items.pop();
fruits.pop(0); → pop() always removes the last item and does not take an index. To remove the first item use fruits.shift() instead.
names.splice(2); → splice with only an index removes everything from index 2 to the end. To remove just one item, give a count: names.splice(2, 1).

Key Term

pop(), shift(), splice()
Array methods that remove items and change the original array: pop removes the last item, shift removes the first, splice(index, count) removes count items starting at index.

Fill in the Blanks

1. let songs = ["Rock", "Pop", "Jazz"]; songs.pop(); console.log(songs);
Hint: Type the method name that removes the last item from the array.
2. let line = ["Zoe", "Leo", "Isla"]; line.shift(); console.log(line);
Hint: Type the method name that removes the first item from the array.
3. let nums = [10, 20, 30, 40]; nums.splice(2, 1); console.log(nums); // [10, 20, 40]
Hint: Type the index of the item to remove (counting from 0). Check the logged result to work it out.
4. let scores = [5, 6, 7, 8, 9]; scores.splice(1, 2); console.log(scores); // [5, 8, 9]
Hint: Type how many items to remove, starting at index 1. Compare the original array with the result.
5. let bag = ["pen", "ruler", "book"]; bag.splice(1, 1); // removes "ruler" console.log(bag.length); // 2
Hint: Type the method that removes items from any position using an index and a count.

Spot the Error

Question 1
A let stack = [5, 6, 7];
B stack.push(8);
C stack.pop;
D console.log(stack);
Line C — pop is a method, so it needs parentheses to run. Without them the line does nothing and no item is removed. It should be stack.pop();
Question 2
A let line = ["A","B","C","D"];
B line.shift();
C line.pop();
D console.log(line.length()); // 2
Line D — length is a property, not a method, so it has no parentheses. It should be line.length. After shift and pop, 2 items remain.
Question 3
A let nums = [10, 20, 30, 40];
B nums.slice(1, 2);
C console.log(nums);
Line B — slice only copies part of an array and leaves the original unchanged. To remove items from the original array, use nums.splice(1, 2);
Question 4
A let pets = ["cat","dog"];
B pets.splice(0, 1);
C console.log(pets[1]); // dog
Line C — splice(0, 1) removed "cat", so only "dog" is left, at index 0. Index 1 is beyond the end and gives undefined. It should be pets[0].
Question 5
A const bag = ["pen" "ruler"];
B bag.pop();
C console.log(bag);
Line A — Array items must be separated by commas. A comma is missing between "pen" and "ruler". It should be ["pen", "ruler"].

Student with a class code? Join your class →