DekGenius.com
Team LiB   Previous Section   Next Section

Chapter 9. Arrays

Chapter 8 documented the JavaScript object type -- a composite data type that holds named values. This chapter documents arrays -- a composite data type that holds numbered values. Note that the arrays we'll discuss in this chapter are different from the associative arrays described in the previous chapter. Associative arrays associate values with strings. The arrays described in this chapter are just regular numeric arrays; they associate values with non-negative integers.

Throughout this book, we often treat objects and arrays as distinct data types. This is a useful and reasonable simplification; you can treat objects and arrays as separate types for most of your JavaScript programming. To fully understand the behavior of objects and arrays, however, you have to know the truth: an array is nothing more than an object with a thin layer of extra functionality. We see this when we use the typeof operator: applied to an array value, it returns the string "object". Note that the extra functionality of arrays was introduced in JavaScript 1.1. Arrays are not supported in JavaScript 1.0.

This chapter documents basic array syntax, array programming techniques, and methods that operate on arrays.

    Team LiB   Previous Section   Next Section