vibecodai logovibecodai
← All JavaScript lessons

JavaScript · Lesson 6 · 14 min

Arrays — Lists of Things

Store multiple values in one list and loop through them.

You will learn

  • Create an array with square brackets
  • Read items by index starting at 0
  • Loop through an array with for

An array holds a list — favorite colors, high scores, or level names. Each item has a position called an index. The first item is index 0, not 1.

Accessing items

Use colors[0] for the first item and colors.length for how many items are in the list.

Loops + arrays

Combining loops and arrays is powerful. The example prints every fruit in the list one by one.

Try it yourself

Output

Press Run code to see results here.

Tip: Add "mango" with fruits.push("mango") then log the list again.