# LENGTH

#### The function LENGTH returns either the number of items in the given list or the number of characters in a given string.

This function takes a single piece of input: either a single List, or a single string. It returns a Number. If a List was given as input, it returns the number of root-level items in the List. If a string was given as input, it returns the number of characters in the string.

### Declaration

LENGTH(list_of_values) -> length
LENGTH(string) -> length

### Parameters

list_of_values (type: List)
Any list.
string (type: string)
Any string.

### Return Values

length (type: Number)
If a List was given as input, this is the number of root-value items in the list. If a string was given as input, this is the number of characters in the string.

### Examples

The following example takes the string "This string!" and returns the number of characters within it. Note that punctuation and spaces both count as characters:

LENGTH("This string!") -> 12

The above example takes a string as input and returns the number of characters that made it up. The following example takes a List and returns the number of root-level items within it. Note that the List given as input includes the string "This string!" from the above example, and yet the LENGTH function returns a number much smaller than the number returned in the above example; the length of the items within a List makes no difference to the number of items in said List:

LENGTH(["This string!", "Another string.", "A third string"]) -> 3

### Discussion

The LENGTH function counts items in Lists in the same way it would Lists of anything else. This includes Lists of Lists. The following example gives a List of two Lists to the LENGTH function, which outputs 2 – the number of root items in the given List, not the number of items within the Lists within a List:

LENGTH([[1, 2], [3, 4, 5]]) -> 2

In order to count the number of items within the Lists within a List, the LENGTH function must be used in tandem with the FLAT function, such as in the following example:

LENGTH(FLAT([[1, 2], [3, 4, 5]])) -> 5