What Is an Array

This section provides a quick description of what is an array in JavaScript and a tutorial example showing JavaScript array features.

Like many programming languages, JavaScript support arrays allowing you to store and retrieve a list of elements.

But unlike many other languages, JavaScript does not have an explicit array data type. Instead, it provides you an Array object type to let you create arrays as objects. Here are the main features of an array in JavaScript:

Here is a tutorial example JavaScript that shows you some of the features mentioned above:

<html>
<!-- Array_Features.html
   Copyright (c) 2002 HerongYang.com. All Rights Reserved.
-->
<head><title>Array Features</title></head>
<body>
<pre>
<script type="text/javascript">

   // Creating a new array of mixed data types
   var account = ["Saving", 999.99, true];

   // Store new value to the array
   account[2] = false;
   
   // Retrieving an element
   document.write("Account type: "+account[0]+"\n");

   // Calling an array method
   account.push(5.25/100);
   document.write("Interest rate: "+account[3]*100+"%\n");
</script>
</pre>
</body>
</html>

The output of this sample JavaScript is:

Account type: Saving
Interest rate: 5.25%

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

Creating, Accessing, and Manipulating Arrays

What Is an Array

 Creating an Array Object

 Accessing Array Elements with Indexes

 Truncating and Iterating Array Elements

 Array Object Instance Methods

 Array Object Instance Method Examples

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 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

 AJAX (Asynchronous JavaScript And XML)

 References

 Full Version in PDF/EPUB