CJCoding With Joseph
15free / daySign inCreate account

JavaScript For Web

Arrays & Looping

Up until now, we have been working with single elements like one button, one paragraph, or one div. But in real websites, you will often need to work with many elements at once. For example, updating all buttons, styling all cards, or deleting all comments.

To do that effectively, you need to understand two related concepts:

  1. Arrays - lists of data in JavaScript

  2. Looping - going through every item in that list or every element on a page


Arrays in JavaScript

An array is a special type of variable that can store more than one value at a time. Instead of creating a separate variable for each value, you can store them all together inside one array.

Each item in an array has a specific position called an index, and the first item always starts at index 0. This means that if you have three items, their positions are 0, 1, and 2.

Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 10 more lessons in JavaScript For Web.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.