Skip to content

Function: getType()

ts
function getType(value): string;

Gets the precise type of a value using Object.prototype.toString. 使用Object.prototype.toString获取值的精确类型。

Parameters

ParameterTypeDescription
valueanyThe value to get the type of / 要获取类型的值

Returns

string

The type name of the value / 值的类型名称

Example

typescript
getType(42) // => "Number"
getType("hello") // => "String"
getType([1, 2, 3]) // => "Array"
getType({}) // => "Object"
getType(null) // => "Null"
getType(undefined) // => "Undefined"
getType(/regex/) // => "RegExp"
getType(new Date()) // => "Date"
getType(() => {}) // => "Function"
getType(new Map()) // => "Map"
getType(new Set()) // => "Set"

Since

1.0.0

Released under the MIT License.