JavaScript Arrays

From Techotopia
Revision as of 14:06, 15 May 2007 by Neil (Talk | contribs)

Jump to: navigation, search

In Introducing JavaScript Variables and JavaScript Variable Types we looked at storing data (such as numbers, strings and boolean true or false values) in memory locations known as variables. The variable types covered in those chapters were useful for storing one value per variable. Often, however, it is necessary to group together multiple variables into a self contained object. This is where the concept of JavaScript Arrays comes in.

What is an Array

A JavaScript array is an object that contains a number items. Those items can be variables (such as strings or numbers) or even other objects (such as Image objects or custom objects which you as a JavaScript developer have created). Once you have grouped all the items into the array you can then perfrom tasks like sorting the array items into alphabetical order, accessing and changing the value assigned to each array item and passing the group of items as an argument to a JavaScript function (see by passing just the array object.