Lesson 23 of 48
48%
JavaScript Arrays
An array is an ordered list of values.
It is like a row of toy cubbies. Each cubby has a number.
The first cubby is number 0.
1
Make an array
2
Read items
3
Change items
4
Length
5
Nested arrays
Create an array
Use square brackets [ ] and commas.
javascript
Read with indexes
Put the index in brackets after the array name.
Remember: counting starts at 0.
javascript
Change an item
Assign a new value to one index.
javascript
Length
.length counts how many items are in the list.
The last index is length minus one.
javascript
Add with push
push adds an item at the end.
javascript
Nested arrays
An array can hold other arrays.
That is like a box of smaller boxes.
javascript
Tip: When you get undefined from an array, check the index. Off by one mistakes are common.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.