0
0
Javascriptprogramming~20 mins

Accessing array elements in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Array Access Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Accessing nested array elements
What is the output of the following code?
Javascript
const arr = [1, [2, 3], 4];
console.log(arr[1][0]);
A[2, 3]
B3
Cundefined
D2
Attempts:
2 left
πŸ’‘ Hint
Remember that arr[1] is an array itself, so you need to access its elements by index.
❓ Predict Output
intermediate
2:00remaining
Accessing array elements with negative index
What will be the output of this code?
Javascript
const arr = [10, 20, 30];
console.log(arr[-1]);
A30
B-1
Cundefined
DSyntaxError
Attempts:
2 left
πŸ’‘ Hint
JavaScript arrays do not support negative indices like some other languages.
❓ Predict Output
advanced
2:00remaining
Accessing array elements after modification
What is the output of this code?
Javascript
const arr = [5, 10, 15];
arr[5] = 25;
console.log(arr.length);
console.log(arr[3]);
A
6
undefined
B
3
undefined
C
6
0
D
5
undefined
Attempts:
2 left
πŸ’‘ Hint
Setting an element at index 5 changes the length of the array.
❓ Predict Output
advanced
2:00remaining
Accessing array elements with destructuring
What will be logged by this code?
Javascript
const arr = [100, 200, 300];
const [a, , c] = arr;
console.log(a, c);
A100 300
B100 200
C200 300
Dundefined undefined
Attempts:
2 left
πŸ’‘ Hint
Destructuring skips the second element with the empty comma.
❓ Predict Output
expert
2:00remaining
Accessing array elements with dynamic keys
What is the output of this code?
Javascript
const arr = [1, 2, 3];
const key = '1';
console.log(arr[key]);
Aundefined
B2
C1
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Array indices are converted to strings internally.