Which of the following is the correct way to create an array in JavaScript?
A
let arr = [1, 2, 3]; B
let arr = new Array(1, 2, 3); C
let arr = Array.of(1, 2, 3); D
All of the above
Analysis & Theory
All three are valid ways to create arrays in JavaScript.
What is the index of the first element in an array?
A
0 B
1 C
-1 D
Depends on the browser
Analysis & Theory
JavaScript arrays are zero-indexed, so the first element is at index 0.
How can you find the length of an array?
A
arr.size B
arr.length() C
arr.length D
size(arr)
Analysis & Theory
`arr.length` returns the number of elements in the array.
What will `arr[arr.length - 1]` return?
A
First element B
Last element C
Middle element D
Error
Analysis & Theory
`arr.length - 1` gives the last index of the array.
Which method adds an element to the end of an array?
A
push() B
pop() C
shift() D
unshift()
Analysis & Theory
`push()` appends an element to the end of the array.
Which method removes the last element of an array?
A
pop() B
shift() C
splice() D
remove()
Analysis & Theory
`pop()` removes the last element and returns it.
Which method adds an element to the beginning of an array?
A
push() B
unshift() C
prepend() D
addStart()
Analysis & Theory
`unshift()` adds elements to the start of the array.
What does `arr.indexOf(3)` return?
A
The index of the first occurrence of 3 B
The value 3 C
True or False D
Removes the value 3
Analysis & Theory
`indexOf()` returns the index of the first match of the given value.
Which method joins all array elements into a string?
A
combine() B
join() C
merge() D
concat()
Analysis & Theory
`join()` creates a single string from all elements of an array.
What will `Array.isArray([])` return?
A
false B
true C
null D
undefined
Analysis & Theory
`Array.isArray()` checks if a value is an actual array and returns `true`.