Recall & Review
beginner
How do you add an element to the end of an array in JavaScript?
Use the
push() method. For example, arr.push(element) adds element to the end of arr.Click to reveal answer
beginner
What method removes the last element from an array?
The
pop() method removes the last element and returns it. It changes the original array.Click to reveal answer
beginner
How can you add an element to the beginning of an array?
Use the
unshift() method. For example, arr.unshift(element) adds element to the start of arr.Click to reveal answer
intermediate
What does the
splice() method do?It can add, remove, or replace elements in an array at any position. For example,
arr.splice(start, deleteCount, item1, item2) removes deleteCount elements from start and inserts new items.Click to reveal answer
beginner
How do you change the value of an element at a specific index in an array?
Assign a new value directly using the index. For example,
arr[2] = newValue changes the third element to newValue.Click to reveal answer
Which method adds an element to the end of an array?
✗ Incorrect
The
push() method adds an element to the end of an array.What does
arr.pop() do?✗ Incorrect
pop() removes and returns the last element of the array.How do you remove elements from the middle of an array?
✗ Incorrect
splice() can remove elements from any position in the array.Which method adds elements to the beginning of an array?
✗ Incorrect
unshift() adds elements to the start of an array.How do you change the value of the second element in an array named
arr?✗ Incorrect
Array indexes start at 0, so the second element is at index 1.
Explain how to add and remove elements from both ends of an array in JavaScript.
Think about methods that work at the start and end of the array.
You got /6 concepts.
Describe how the splice() method can be used to modify an array.
Consider how you can remove and add items anywhere in the array.
You got /6 concepts.