Skip to content

length - Get the length of a string

The length function will return a count of the number of individual characters in a string.

Syntax

Like many functions in DataPrime, length supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

length(value: string): number
value: string.length(): number

Arguments

NameTypeRequiredDescription
valuestringtrueThe string whose length we seek

Example - Basic usage

There are two ways to invoke length, either as a function of a string or as a standalone function.

Consider the following document:

{
    "str_val": "Hello world!"
}

If I wish to get the length of str_val, and store it in a new field entitled str_val_len, I can do so in two ways:

create str_val_len from length(str_val)
create str_val_len from str_val.length()