es-toolkit/docs/reference/predicate/isMap.md
HyunWoo Choi 2acc21175d
feat(isMap): add isMap (#600)
* feat : add isMap function

* feat : add isMap bench

* docs : isMap
2024-09-26 16:32:22 +09:00

776 B

isMap

Checks if the given value is a Map.

This function tests whether the provided value is an instance of Map. It returns true if the value is a Map, and false otherwise.

This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to Map.

Signature

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

Parameters

  • value (unknown): The value to check if it is a Map.

Returns

(value is Map<any, any>): true if the value is a Map, false otherwise.

Examples

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