How to check if a Map or Set is empty?

You use its size property. Both Maps and Sets have it (here and here).

const populatedSet = new Set(['foo']);
console.log(populatedSet.size);  // 1

const populatedMap = new Map([['foo', 1]]);
console.log(populatedMap.size);  // 1

(Side note: WeakMaps and WeakSets don’t have size or several other features their “strong” counterparts have, in order to keep their implementations, and code using them, sane. 🙂 Where they have similar functionality, they offer the same API, but they aren’t subclasses.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)