Skip to content

count ​

The count function returns the number of elements in an array or characters in a string.

Syntax ​

typescript
count(array: any[] | string): number;

Parameters ​

NameTypeDescription
arrayany[] | stringSource array or string

Returns ​

TypeDescription
numberNumber of elements or characters

Examples ​

typescript
count([1, 2, 3]); // => 3
count("abc"); // => 3
count([]); // => 0

Notes ​

  • Returns 0 for empty arrays or strings.
  • Useful for size validation.

References ​

Released under the MIT License.