5.10. Helper Objects

5.10.1. Array

An Array is used to hold a collection of elements. For example, if we wanted to work with all of the li elements in a list, we would keep track of them all by keeping them in an Array. An array allows us to work with each element in turn because each element in the array can be accessed by its number.

Consider the following list.

  • Luther
  • Coe
  • Simpson
  • Central
  • Wartburg

The first thing in our list is Luther: its position in the list is 0. The second thing on the list is Coe: its position is 1. The last thing on the list (appropriately) is Wartburg: its position is 4.

We can get the elements from the list and put them in an array using the querySelectorAll funciton.

We can combine iteration and arrays to work with each element in an array as follows:

5.10.2. String

You have attempted of activities on this page