Using Arrays

Arrays are a powerful feature of most programming languages, and they are also available to the JavaScripter! An array enables you to store several separate values within a single variable. Usually, all these values have a connecting theme (such as days of the week). Arrays are great because when you know how to use them they can really simplify your code—saving you from having to create a bunch of separate variables with similar names.

So, let's look at how to create and use arrays. The example here will be used to hold the seven days of the week.

The first thing you need to do is to bring the array into existence:

 <html> <head> <title>A Simple Page</title> <script language="JavaScript"> <!-- Cloaking device on! var days_of_week ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.