# Merge object and split array by size, Trộn object và tách array theo size (ok)

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1E4Gk2ppVKb4olmnun%2Fuploads%2F0QZjmccjnzaztDf89QET%2FScreenshot_1.png?alt=media\&token=87db3b5c-2c15-4002-9b14-9d65d8b3e173)

![](https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1E4Gk2ppVKb4olmnun%2Fuploads%2FWoSMOikxV1Ref3ElZEDf%2FScreenshot_2.png?alt=media\&token=e1d634e8-7104-42b5-8848-662d54d0df78)

```
function chunkArrayInGroups(arr, size) {
    var newArr = [];
    for (var i = 0; i < arr.length; i += size) {
      newArr.push(arr.slice(i, i + size));
    }
    return newArr;
  }
```

Áp dụng trong App

```
var pi = await chunkArrayInGroups(sub_array2, 100).reduce(async (promise, arr) => {
        await promise;
        var body2 = {
          'app': appid,
          'records': arr
        };
        var resp = await kintone.api('/k/v1/records', 'POST', body2);
        console.log(resp);
      }, Promise.resolve());
      // App 3412
```
