# 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](../../variable-data-types/the-list-data-type), or a single [string](../../variable-data-types/the-text-variable-data-type). It returns a [Number](../../variable-data-types/the-number-variable-data-type). 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

```javascript
LENGTH(list_of_values) -> length
```

```javascript
LENGTH(string) -> length
```

&#x20;

#### 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:

```javascript
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:

```javascript
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:&#x20;

```javascript
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](flat) function, such as in the following example:

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