0
0
Javascriptprogramming~5 mins

Modifying arrays in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Apush()
Bpop()
Cshift()
Dunshift()
What does arr.pop() do?
AAdds an element to the end
BAdds an element to the start
CRemoves the first element
DRemoves the last element
How do you remove elements from the middle of an array?
AUsing <code>slice()</code>
BUsing <code>splice()</code>
CUsing <code>push()</code>
DUsing <code>pop()</code>
Which method adds elements to the beginning of an array?
Aunshift()
Bpush()
Cpop()
Dshift()
How do you change the value of the second element in an array named arr?
Aarr.set(2, newValue)
Barr[2] = newValue
Carr[1] = newValue
Darr.change(1, newValue)
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.