---
schema_version: "1"
id: 7575ca3609233e871184a9d0a61e54ddc0694ada7922d36a593e91344efac31b
title: divideBy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-arrays-functions-divideby.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-arrays-functions-divideby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 76b63af9a910f28ccc92fee6514692ca394f70245ad78ddadfbb69699c3510f2
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# divideBy

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## divideBy(Array<T>, Number): Array<Array<T>>

Breaks up an array into sub-arrays that contain the specified number of elements.

When there are fewer elements in the input array than the specified number, the function fills the
sub-array with those elements. When there are more elements, the function fills as many sub-arrays
needed with the extra elements.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>items</code></p></td><td><p>Items in the input array.</p></td></tr><tr><td><p><code>amount</code></p></td><td><p>The number of elements allowed per sub-array.</p></td></tr></tbody></table>

### Example

This example breaks up arrays into sub-arrays based on the specified `amount`.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Arrays
output application/json
---
{
  "divideBy" : [
      { "divideBy2" : [1, 2, 3, 4, 5] divideBy 2 },
      { "divideBy2" : [1, 2, 3, 4, 5, 6] divideBy 2 },
      { "divideBy3" : [1, 2, 3, 4, 5] divideBy 3 }
  ]
}
```

#### Output

```JSON
{
 "divideBy": [
  {
    "divideBy2": [
      [ 1, 2 ],
      [ 3, 4 ],
      [ 5 ]
    ]
  },
  {
    "divideBy2": [
      [ 1, 2 ],
      [ 3, 4 ],
      [ 5, 6 ]
    ]
  },
    {
      "divideBy3": [
        [ 1, 2, 3 ],
        [ 4, 5 ]
      ]
    }
 ]
}
```
