JavaScript Tutorials - Herong's Tutorial Examples - 2.33, by Herong Yang
Accessing Array Elements with Indexes
This section provides a tutorial example on how to access array elements with element indexes.
Array elements can be access with array indexes with several simple rules:
Here is a tutorial example JavaScript that shows you how to store or retrieve array elements with element indexes:
<html> <!-- Access_Array_Elements.html Copyright (c) 2002 HerongYang.com. All Rights Reserved. --> <head><title>Access Array Elements</title></head> <body> <pre> <script type="text/javascript"> // Creating an empty array var glossary = new Array(); // Adding the first element glossary[0] = "JavaScript"; // Adding the second element at index 10 // This extends the array length to 11 glossary[10] = "Web"; document.write("Element at index of 0: "+glossary[0]+"\n"); document.write("Element at index of 5: "+glossary[5]+"\n"); document.write("Element at index of 10: "+glossary[10]+"\n"); document.write("Element at index of 15: "+glossary[15]+"\n"); </script> </pre> </body> </html>
The output of this sample JavaScript is:
Element at index of 0: JavaScript Element at index of 5: undefined Element at index of 10: Web Element at index of 15: undefined
Table of Contents
ECMAScript Language Specification and JavaScript Dialects
Data Types, Variables and Expressions
►Creating, Accessing, and Manipulating Arrays
►Accessing Array Elements with Indexes
Truncating and Iterating Array Elements
Array Object Instance Method Examples
Defining and Calling Functions
Web Browser Supporting JavaScript
Server-Side and Client-Side Web Scripting
Defining Your Own Object Types
Inheritance of Properties and Methods through the Prototype Object Chain
'jrunscript' - JavaScript Shell Command from JDK
Using Functions as "Function" Objects
Introduction to Built-in Object Types
W3C's Document Object Model (DOM) Specifications