Skip to content

getInstanceType ​

The getInstanceType function returns the constructor (class) name of an instance, or null if not applicable.

Syntax ​

typescript
getInstanceType(value: any): string | null;

Parameters ​

ParameterTypeDescription
valueanyValue to be inspected

Returns ​

TypeDescription
string | nullConstructor name or null if not applicable

Examples ​

typescript
getInstanceType([]); // => "Array"
getInstanceType(new Map()); // => "Map"
getInstanceType(123); // => null

Notes ​

  • Useful for identifying object instance types.

References ​

Released under the MIT License.