Array.isTypedArray = function(inArray){
if(inArray){
const prototype = Object.getPrototypeOf(inArray);
return prototype ? prototype.hasOwnProperty("BYTES_PER_ELEMENT") : false;
}
return false;
}
console.log(" 'Iam' a typed array ", Array.isTypedArray([1,2,3]));
console.log("[1,2,3] is typed array ", Array.isTypedArray([1,2,3]));
console.log("new Int8Array([1,2,3]) is typed array ", Array.isTypedArray(new Int8Array([1,2,3])));
console.log("new BigUint64Array() is typed array ", Array.isTypedArray(new BigUint64Array()));
console.log("new Uint8ClampedArray([1,2,3]) is typed array ", Array.isTypedArray(new Uint8ClampedArray([1,2,3])));
console.log("new Float32Array([1,2,3]) is typed array ", Array.isTypedArray(new Float32Array([1,2,3])));
console.log("new BigUint64Array() is typed array ", Array.isTypedArray(new BigUint64Array()));
console.log("new Set() is typed array ", Array.isTypedArray(new Set()));
console.log("null is typed array ", Array.isTypedArray(null));
console.log("undedined is typed array ", Array.isTypedArray(undefined));
console.log("{} is typed array ",Array.isTypedArray({}));
function getType(obj){
return Array.isTypedArray(obj) ? obj.constructor.name: (typeof obj)
}
console.log("Type of Array ", getType(new Array()));
console.log("Type of Int8Array ", getType(new Int8Array()));
console.log("Type of Uint8Array ",getType( new Uint8Array()));
console.log("Type of Uint8ClampedArray ",getType( new Uint8ClampedArray()));
console.log("Type of Int16Array ", getType(new Int16Array()));
console.log("Type of Float32Array ", getType(new Float32Array()));
console.log("Type of BigInt64Array ", getType(new BigInt64Array()));
console.log("Type of BigUint64Array ", getType(new BigUint64Array()));