Estoy usando la versión de Chrome Version 101.0.4951.64 (Official Build) (arm64) en un nuevo macbook pro m1. ¿Es el comportamiento esperado que
Array.isArray(new Float32Array([0, 1, 2]))
devuelve false ?
console.log(Array.isArray(new Float32Array([1, 2, 3])));Las matrices con tipo no son técnicamente matrices, son TypedArray y tienen su propio tipo:
let floatArr = new Float32Array(); console.log(Object.prototype.toString.call(floatArr)); console.log(Object.prototype.toString.call([]));Y de acuerdo con los documentos web de MDN :
Las matrices escritas en JavaScript son objetos similares a matrices
...
Sin embargo, las matrices con tipo no deben confundirse con las matrices normales, ya que llamar aArray.isArray()en una matriz con tipo devuelvefalse.
TypedArrays no son matrices.
console.log(new Uint32Array instanceof Array) El equivalente de Array.isArray() para TypedArrays es ArrayBuffer.isView() :
const typed = new Float32Array(1024); const arr = new Array(1024); console.log(Array.isArray(typed)); // false console.log(Array.isArray(arr)); // true console.log(ArrayBuffer.isView(typed)); // true console.log(ArrayBuffer.isView(arr)); // false con la particularidad de que también devolverá true para objetos DataView.