O'Reilly logo

JavaScript: The Definitive Guide, 6th Edition by David Flanagan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Typed Arrays and ArrayBuffers

As you know from Chapter 7, JavaScript arrays are general-purpose objects with numeric properties and a special length property. Array elements can be any JavaScript value. Arrays can grow or shrink dynamically and can be sparse. JavaScript implementations perform lots of optimizations so that typical uses of JavaScript arrays are very fast. Typed arrays are array-like objects (Array-Like Objects) that differ from regular arrays in some important ways:

  • The elements of a typed array are all numbers. The constructor used to create the typed array determines the type (signed or unsigned integers or floating point) and size (in bits) of the numbers.

  • Typed arrays have a fixed length.

  • The elements of a typed array are always initialized to 0 when the array is created.

There are eight kinds of typed arrays, each with a different element type. You can create them with the following constructors:

ConstructorNumeric type
Int8Array()signed bytes
Uint8Array()unsigned bytes
Int16Array()signed 16-bit short integers
Uint16Array()unsigned 16-bit short integers
Int32Array()signed 32-bit integers
Uint32Array()unsigned 32-bit integers
Float32Array()32-bit floating-point value
Float64Array()64-bit floating-point value: a regular JavaScript number

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required