When you want to work with multiple related values, you can use the Array object. The new keyword is required when creating an array of object type data, like an array of string objects. The new keyword is not required when creating an array of simple variable types, like integers. In this article you learn about mutidimensional arrays, and study examples of how to use each Array Object method.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

Using the Java Script Array Object

An array is a structure for storing multiple data values. Each value in an array is given an index number. To access a particular data item in an array, use the name of the array and the index number of the particular data item.

Creating an Array

To create an Array, use new keyword. The code shown below creates an array named color that can hold three data items.

var color = new Array(3);

Putting Data into an Array

To enter data into an array, create a series of assignment statements, one for each data item in the array. The code shown below populates the color array with the names of three colors.

color[0] = "red";
color[1] = "green";
color[3] = "blue";

Note that array indexes are zero-based, in other words the index values start with 0 for the first element.

The new keyword is required only when creating an array with object type data. In the previous example we created an array of string objects. The new keyword is not required when creating an array of simple variable types. The code shown below creates and populates an array with integers.

var digit = [1, 2 ,3];

The code shown below creates and populates an array with characters.

var char = ['a', 'b' ,'c'];

Accessing Array Values

To access a particular data item in an array, use the item's index number. The code shown below displays the value of the second data item in the array of characters created above.

alert(char[1]);

Output:

b

To access the entire contents of an array, use the name of the array without an index number. The code shown below displays the value of all the data items in the array of characters.

alert(char);

Output:

a,b,c

Web Design Sections

RSS Feed RSS Feed

Easy Java Script Code
Easy Java Script Windows
Easy Rollovers
Easy Picture Transition Effects
Easy Moving Popup Code
Easy Slide Show Code
Easy Slide Show Code With Linked Slides
Slide Show with Different Size Images
Easy Picture Zoom Code
Easy Picture Panning Code
Easy Java Script Animation
Easy JavaScript Picture Selector Code
Easy Animated Banners with Java Script
Easy Java Script Form Validation
Easy Drag n Drop Code
Easy Graph Generating Code
Easy Code to Sort a Table by Column
Easy Fading Text Banner Code
Easy Expanding Banner Code
Calendars for Your Website
Date Picker For Your Web Site
Calculators For Your Web Site
Loan Payment Calculator
Length Units Converter
Body Mass Index
Fahrenheit to Celsius Converter
Decimal to Hexidecimal Converter
Easy Code for Screen Tape Adding Machine
Code for Java Script Circle⁄Sphere Calculator
Round a Float to 4 Digits to the Right of the Decimal Point
Make Your Own Graphical Digital Clock
Let Your Web site Visitors Set Font Size
How to Disable the Browser Back Button
Add More Bang to Your Content With Keyword Popup Menus
Put a Music Off Switch on Your Webpage
Java Script Random Password Generator
Password Protection Using Java Script
Replace Drop-down with Drag-and-drop
Submit Forms Without CGI
Code for a Less annoying Popup Window
Using the Java Script Array Object
Using the Java Script Date Object
Java Script Message Boxes
How to Shuffle the Deck With Java Script
Web Site Menus : Which Section Am I In?
How Far Did the User Scroll?
Where Did the User Click?
Four Ways to Use Java Script Event Handlers
Create Your Own Database Using Only Notepad : CDV

Get paid cash typically $4 to $25 for each survey you complete!

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269