Objects with Indexed Properties

This section provides a quick description of indexed properties and indexed methods. A tutorial example is provided on how to create and access indexed properties and indexed methods.

JavaScript also supports objects with indexed properties with the following features:

Here is a tutorial example on how to define and access object's indexed properties and indexed methods in two formats: array format and associate array format:

<!-- Object_Indexed_Properties.html
   Copyright (c) 2008 HerongYang.com. All Rights Reserved.
<title>Objects with Indexed Properties</title>
<script type="text/javascript">
// Using "this" to get the properties
function myToString() {
   return '"'+this.title + '" by '+this.author;

   // Using object literal format
   var myBook = {
      author: "Herong Yang",
      title: "JavaScript Tutorials",
      3: 2008,
      price: "Free",
      4: myToString

   // Adding a new indexed property   
   myBook[9] = "Programming";

   // An index property can not be accessed with (.)
   // document.writeln("myBook.3: "+myBook.3);

   // Getting indexed property values
   document.writeln("myBook[3]: "+myBook[3]);
   document.writeln("myBook['3']: "+myBook['3']);
   document.writeln("myBook[4]: "+myBook[4]);
   document.writeln("myBook[9]: "+myBook[9]);

   // Checking property data types

The output of this tutorial example matches my expectation:

myBook[3]: 2008
myBook['3']: 2008
myBook[4]: function myToString() {
    return "\"" + this.title + "\" by " + this.author;
myBook[9]: Programming

"JavaScript Tutorials" by Herong Yang

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

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

Introduction to Objects

 What Is an Object?

 Objects of "Object" Data Type

 Adding and Deleting Object Own Properties

 Adding and Deleting Object Own Methods

 Using "this" Keyword to Represent Current Object

 Object Literals of the "Object" Type

 Objects and Associate Arrays

Objects with Indexed Properties

 Differences between "Object" and "Array"

 Using "Array" Objects as "Object" 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)


 Full Version in PDF/EPUB