检查 Map 中是否存在密钥

要检查 Map 中是否存在密钥,请使用 .has() 方法:

map.has(key);

例:

const map = new Map([[1, 2], [3, 4]]);
console.log(map.has(1)); // true
console.log(map.has(2)); // false