Namespace: Basic:size

Basic:size

Source:

Methods

size(target, countStringCharactersopt, nullable) → {Number|null}

Determine the (value) size of a collection.

A collection is an object with countable values:

  • Arrays return their length
  • Sets and Maps return their size
  • Strings return their (character) length
  • Iterators return the length of their value list
  • Objects return the length of their value list
  • any object implementing .values() returns the length of the returned value list
Parameters:
Name Type Attributes Default Description
target Object | Array | Set | Map | String | Iterable

a collection to determine the (value) size of

countStringCharacters Boolean <optional>
<nullable>
true

if we want to determine the length of a string, we'd normally like to count actual characters, but length normally returns the technical length counting more than one for unicode chars, set this to "false" to use technical length instead of characters

Source:
Returns:
the size of the collection or null if no size could be determined
Type
Number | null
Example
size('日本国💩👻');
=> 5
size('日本国💩👻', false);
=> 7
size({a : 1, b : new Date(), c : [1, 2, 3]});
=> 3
size(['test', 'test', 'test']);
=> 3
size(new Set(['test1', 'test2', 'test3']));
=> 3
size(new Set(['test1', 'test2', 'test3']).values());
=> 3
size(new Map([[1, 1], [new Date(), new Date()], ['foo', 'bar']]));
=> 3
size(new Map([[1, 1], [new Date(), new Date()], ['foo', 'bar']]).values());
=> 3
size(null);
=> null
size(undefined);
=> null