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

# divideBy

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

## divideBy<T>(items: Array<T>, amount: 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 ]
      ]
    }
 ]
}
```

## divideBy(items: Null, amount: Any): Null

Helper function that enables `divideBy` to work with a `null` value.

_Introduced in DataWeave version 2.4.0._
