home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


JavaScript: The Definitive Guide

Previous Chapter 8
Arrays
Next
 

8.9 Array Summary

JavaScript array creation, usage, and compatibility techniques can be confusing. Here are the main points of this chapter in review:

  • Arrays and objects are the same thing in JavaScript. Any object can have array elements, and any array can have object properties.

  • In Navigator 3.0, there are three methods that can be used to manipulate arrays:

    1. You can can convert an array, and all of its elements into a single string with the Array.join() method.

    2. You can reverse the order of elements in an array with the Array.reverse() method.

    3. You can sort the elements of an array with the Array.sort() method.

  • In Navigator 3.0 and Internet Explorer 3.0, array elements and object properties do not overlap and cannot overwrite each other. There is an Array() constructor, and arrays created with this constructor have a (read-only in IE 3.0) length property that is automatically maintained so that it always contains a value one greater than the largest index of the array.

  • In Navigator 2.0, object properties and array elements overlap; when you create a new property, it is as if you added a new array element one higher than the highest existing element. There is no built-in Array() constructor, but you can write your own. Also, there is no automatically maintained length property, but it is common to reserve element 0 of an array for a size property (which you update yourself as the array grows).

  • For many algorithms, the size of an array is maintained in a variable externally to an array, and there is no need for a length or size property.

  • All arrays in JavaScript are implemented as associative arrays, and can be "sparse"--i.e., they can contain non-contiguous elements. Usually, though, you'll use arrays as if they were non-associative, fixed-size arrays like those found in C, C++, and Java.


Previous Home Next
Built-in Arrays Book Index Further Topics in JavaScript

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell