length

Modified on Thu, 9 Jul at 10:49 AM

length

TABLE OF CONTENTS

Return the length of a string, array or object

Definition

number length(string|array|object $subject)

Returns the length of the given argument using the following types rules:

  • string: returns the number of code points in the string
  • array: returns the number of elements in the array
  • object: returns the number of key-value pairs in the object

Parameters

string | array | object $subject

Data to calculate the length of.

Returns

number

Length of input.

Examples

Transformation
{
  a: length(`abc`),
  b: length(`[]`),
  c: length(['a', 'b', 'c']),
  d: length(`{}`),
  e: length({name: 'Mt. Everest', height: '8849m'}),
  f: length(not_there),      // Error
  g: length(`123`),          // Error
  h: length(`true`),         // Error
  i: length(`null`)          // Error
}
Result
{
  "a": 3,
  "b": 0,
  "c": 3,
  "d": 0,
  "e": 2
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article