I know this is not a very good solution but I think you can achieve the same kind of behavior using a hacky way. Actually, I don't like this kind of solution. I used Uint8Array.__proto__
, I have no idea why the prototype of Uint arrays doesn't exist in chrome.
const uint8Array = new Uint8Array();
const uint16Array = new Uint16Array();
const uint32Array = new Uint32Array();
console.log(uint8Array instanceof Uint8Array.__proto__); //true
console.log(uint16Array instanceof Uint8Array.__proto__); //true
console.log(uint32Array instanceof Uint8Array.__proto__); //true
Edit:
const typedArrays = [new Uint8Array(), new Uint16Array(), new Uint32Array()];
const result = typedArrays.every(elem => elem instanceof Uint8Array.__proto__);
console.log(result);
So, you can check any typed array using Uint8Array.__proto__
.
Edit 2:
const isTypedArray = (arg) => {
return arg instanceof Uint8Array.__proto__;
};
console.log(isTypedArray(uint8Array));// true
console.log(isTypedArray(uint16Array));// true
console.log(isTypedArray(uint32Array));// true