es-toolkit/docs/zh_hans/reference/predicate/isMap.md
hyesung oh 893ed163f3
Some checks failed
CI / codecov (push) Has been cancelled
Release / release (push) Has been cancelled
docs(predicate): append docs fot isSet and isMap (#604)
2024-09-27 10:28:23 +09:00

725 B

isMap

检查给定值是否为 Map

此函数测试提供的值是否为 Map 的实例。 如果值是 Map,则返回 true,否则返回 false

此函数还可以作为 TypeScript 中的类型谓词,将参数的类型缩小为 Map

签名

function isMap(value: unknown): value is Map<any, any>;

参数

  • value (unknown): 要检查的值。

返回值

(value is Map<any, any>): 如果值是 Map,则为 true;否则为 false

示例

const value1 = new Map();
const value2 = new Set();
const value3 = new WeakMap();

console.log(isMap(value1)); // true
console.log(isMap(value2)); // false
console.log(isMap(value3)); // false