One list holds the whole week
The rain gauge was read every morning this week. Each reading is that day's rain in millimetres. Seven numbers fit in one list, a row of boxes.
Loading lab…
Step 1 of 3
- Seven readings, in one list. Positions run 0 to 6.
.lengthcounts every box: 7.- An empty list still has a length. It is 0.
The rule
A list holds many values, in order, under one name. Ask .length for the count — 0 for an empty list.
const rain = [6, 46, 2, 8, 0, 4, 4];
The word const gives the list the name rain. The first reading is at position 0, so rain[0] is 6.
That is one name for seven numbers.
| Ask | You get |
|---|---|
rain.length | 7 |
[].length | 0 |
rain[0] | 6 |
Remove a reading, and .length changes too. You do not count by hand.
Watch out!
.length is a count, not a position. The count is 7. The last position is 6.