Arrays – Mutating Methods, online
Six activities your students do on their own devices. See who's finished, and their scores.
Arrays – Mutating Methods in one minute
What students need to know
unshift() inserts the value at the beginning of the array. shift() removes and returns the array's first element.
push() adds one or more elements to the end of the array. push, pop, shift, and unshift all mutate the original array.
Mistakes students make
- Use push(), not add(), to add to the end of an array.
- Use pop(), not remove(), to remove the last element.
- push() needs parentheses to actually call the method.
- 'pop' must be lowercase - a capital P causes an error.
What students will learn in this module
Every question in Module 24
Quick questions
- Does push() add an element to the end of an array?AYesBNo
- Does pop() remove the first element of an array?ANoBYes
- Does unshift() add an element to the start of an array?ANoBYes
- Does shift() remove the first element of an array?ANoBYes
- Do these methods change the original array?AYesBNo
Key terms
Students type the meaning of:
push()
Match the pairs
nums.push(4)Match it to what it doesnums.pop()Match it to what it doesAdds an element to the start of an arrayMatch it to what it doesRemoves the first element from an arrayMatch it to what it doesa.add(3);Match it to what it doesb.remove();Match it to what it doesFill in the blanks
nums.____(4);
Hint: Type the method that adds an element to the end of an array.
nums.___();
Hint: Type the method that removes the last element of an array.
nums._______(1);
Hint: Type the method that adds an element to the start of an array.
let first = nums._____();
Hint: Type the method that removes the first element of an array.
scores.____(90);
Hint: Type the method that adds an element to the end of an array.
Spot the error
Question 1
Aa.add(3);Blet a = [1, 2];Cconsole.log(a);
Question 2
Alet b = [1, 2, 3];Bb.remove();Cconsole.log(b);
Question 3
Alet c = [2, 3];Bconsole.log(c);Cc.push;
Question 4
Alet d = [1, 2, 3];Bconsole.log(d);Clet e2 = 5;Dd.Pop();
Question 5
Alet e = [2, 3];Bconsole.log(e);Clet f2 = 1;Dconsole.log(f2);Ee.Push(1);
