Contact Free trial Login

sizeOf

sizeOf(Array<Any>): Number

Returns the number of elements in an array.

Returns 0 if the array is empty.

Example

This example returns a count of elements in the input array.

Source

%dw 2.0
output application/json
---
{
  "arraySize": sizeOf([1,2,3])
}

Output

{
  "arraySize": 3
}

sizeOf(Object): Number

Returns the number of key-value pairs in an input object.

Returns 0 if the object is empty.

Example

This example counts the key-value pairs in an input object.

Source

%dw 2.0
output application/json
---
{
  objectSize: sizeOf({a:1,b:2})
}

Output

{
  "objectSize": 2
}

sizeOf(Binary): Number

Returns the byte length of a binary.

Example

This example returns the size of a binary value that is passed through a variable. The binary is returned by a function in core::Binaries.

Source

%dw 2.0
import * from dw::core::Binaries
var var1 = fromBase64(000000)
output application/json
---

{ "size" : sizeOf(var1) }

Output

{
  "size": 4
}

sizeOf(String): Number

Returns the number of characters (including white space) in an string.

Returns 0 if the string is empty.

Example

This example returns the number of characters in the input strings.

Source

%dw 2.0
output application/json
---
{
  "sizeOfString1" : sizeOf("MuleSoft"),
  "sizeOfSting2" : sizeOf("my string")
}

Output

{
  "sizeOfString1": 8,
  "sizeOfSting2": 9
}