chessweb
chessweb

Reputation: 4645

Typed arrays in JavaScript are not arrays

var a = Int32Array(10);
console.log(Array.isArray(a)); // prints false to the console (Firefox)

Is there a reason why a typed JavaScript array is not an array or is this a bug that needs to be reported?

Upvotes: 1

Views: 124

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382132

No, typed arrays aren't arrays, it doesn't need reporting.

They're a very distinct set of objects with different functions. In the specification, they're described as objects which

present an array-like view of an underlying binary data buffer

A good reason not to confuse them : they don't even offer the functions you have on arrays, for example splice.

It also doesn't follow the spec of Array.isArray as it's not an "Array object" as can be verified by setting the value at an out of range index using the bracket notation and checking the length isn't changed.

Upvotes: 1

Related Questions