fix(curriculum): update description for step 19 of pyramid project (#54474)

This commit is contained in:
BIgChunkyChicken
2024-04-22 22:10:15 +08:00
committed by GitHub
parent a10126c180
commit 8b09caa5f8

View File

@@ -11,11 +11,17 @@ Notice how the value inside your `rows` array has been changed directly? This is
Before moving on, this is a great opportunity to learn a common array use. Currently, your code accesses the last element in the array with `rows[2]`. But you may not know how many elements are in an array when you want the last one.
You can make use of the `.length` property of an array - this returns the number of elements in the array. For example, your `rows` array has 3 elements, so `rows.length` would be `3`.
You can make use of the `.length` property of an array - this returns the number of elements in the array. To get the last element of any array, you can use the following syntax:
Since you know the last element is at index `2`, you can compare that with the length of the array and see it is one less. The last element of an array will always be accessible at the index `length - 1`. You can use that in your bracket notation.
```js
array[array.length - 1]
```
Update your `rows[2]` to access the `rows.length - 1` index instead of the `2` index. You should not see anything change in your console.
`array.length` returns the number of elements in the array. By subtracting `1`, you get the index of the last element in the array. You can apply this same concept to your `rows` array.
Update your `rows[2]` to dynamically access the last element in the `rows` array. Refer to the example above to help you.
You should not see anything change in your console.
# --hints--