Count entries in arrays, strings, maps, sets, and objects
A debugging panel shows a short summary next to every value it inspects, such as Array(3), Map(2) or {…} 4 keys. The number comes from one helper that has to know how each kind of collection reports its size.
Implement sizeOf(value). It returns the number of entries in value.
sizeOf(value) // => number
Uint8Array: their length. Extra non-index properties on an array do not count.'😀' has length 2 in JavaScript but counts as 1 here.size.TypeError.null prototype, class instances): the number of its own enumerable string keys. Inherited keys, non-enumerable keys and symbol keys do not count. A key named length or size is just another key.null, undefined, numbers, booleans, bigints, symbols and functions: 0.sizeOf([1, 2, 3]); // => 3
sizeOf([, , 'x']); // => 3
sizeOf('café'); // => 4
sizeOf('hi 👋'); // => 4
sizeOf(new Map([['a', 1], ['b', 2]])); // => 2
sizeOf(new Set('banana')); // => 3
sizeOf({ id: 7, length: 10 }); // => 2
sizeOf(new Uint8Array(16)); // => 16
sizeOf(null); // => 0
sizeOf(42); // => 0
sizeOf(new WeakMap()); // throws TypeError