Contact Us 1-800-596-4880

to

to(from: Number, to: Number): Range

Returns a range with the specified boundaries.

The upper boundary is inclusive.

Parameters

Name Description

from

Number value that starts the range. The output includes the from value.

to

Number value that ends the range. The output includes the from value.

Example

This example lists a range of numbers from 1 to 10.

Source

%dw 2.0
output application/json
---
{ "myRange": 1 to 10 }

Output

{ "myRange": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }

Example

DataWeave treats a string as an array of characters. This example applies to to a string.

Source

%dw 2.0
var myVar = "Hello World!"
output application/json
---
{
  indices2to6 : myVar[2 to 6],
  indicesFromEnd : myVar[6 to -1],
  reversal : myVar[11 to -0]
}

Output

{
  "indices2to6": "llo W",
  "indicesFromEnd": "World!",
  "reversal": "!dlroW olleH"
}