0
0
Javascriptprogramming~5 mins

Array length property in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the length property of an array represent in JavaScript?
The length property shows how many elements are in the array. It tells you the total number of items stored.
Click to reveal answer
beginner
If you have <code>let arr = [1, 2, 3, 4];</code>, what is <code>arr.length</code>?
The value of arr.length is 4 because there are 4 elements in the array.
Click to reveal answer
intermediate
Can you change the length property of an array? What happens if you set it to a smaller number?
Yes, you can set length to a smaller number. This will remove elements from the end of the array, shortening it.
Click to reveal answer
intermediate
What happens if you set the length property of an array to a larger number?
The array's size increases, but new elements are empty slots (holes). The array has more space but no new values.
Click to reveal answer
intermediate
Is the length property always equal to the number of elements you see when you print the array?
Not always. length counts all elements including empty slots. Some elements might be undefined or missing but still counted.
Click to reveal answer
What does array.length return?
AThe last element in the array
BThe number of elements in the array
CThe sum of all elements
DThe first element in the array
If arr = [10, 20, 30], what is arr.length?
A30
B2
C3
Dundefined
What happens if you set arr.length = 2 on arr = [1, 2, 3, 4]?
AArray becomes [1, 2, 3, 4, 2]
BError is thrown
CArray stays the same
DArray becomes [1, 2]
What is the value of arr.length after arr.length = 5 if arr = [1, 2]?
A5
B3
CUndefined
D2
Does length count empty slots in an array?
AYes, it counts empty slots
BNo, it only counts filled elements
COnly counts numbers
DOnly counts strings
Explain how the length property works in JavaScript arrays and what happens when you change it.
Think about how length relates to array size and content.
You got /4 concepts.
    Describe a real-life example where changing the array length property might be useful.
    Imagine a list of tasks you want to trim or expand.
    You got /3 concepts.