1
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?

chessweb
  • 4,613
  • 5
  • 27
  • 32

1 Answers1

1

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.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • Well, in that case I can't use typed arrays as it would break my method of function overloading in some cases: http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices/29473331#29473331 – chessweb May 04 '15 at 19:14
  • Arrays and Typed Arrays can't be used indifferently. There's a very specific (and constraining) API for typed arrays. – Denys Séguret May 04 '15 at 19:18