Ramda.js R.splitEvery() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.splitEvery(n, list) cuts a list or string into chunks of size n, in order. If the length is not a multiple of n, the last chunk is simply shorter (official Ramda docs). The original is never changed, and R.splitEvery(n) is a reusable function for pipelines.

Stable since v0.16.0: R.splitEvery is not deprecated, experimental, or non-standard. JavaScript arrays have no built-in chunk method; by hand you would loop over Array.prototype.slice().

Syntax

Call R.splitEvery. Start with this line.

Ramda
R.splitEvery(n, list) or R.splitEvery(n)(list)
CallWhat it does
R.splitEvery(n, list) or R.splitEvery(n)(list)Primary signature.
R.splitEvery(...)Call the list helper.

Prefer import { splitEvery } from "ramda" when you want a named import.

Library declarations
Ramda
R.splitEvery(n, list) or R.splitEvery(n)(list)

Parameters

ParameterDescription
nRequired. Number. Chunk size. A positive whole number; 0 or less throws.
listOptional. Array or String. The value to chunk; omit it to get a reusable function

Return Value

Return ValueDescription
*An array of chunks — arrays for a list, strings for a string

Ramda Examples

Example 1 — Chunk a List (Official Sample)

Group seven numbers in threes.

Ramda
const nums = [1, 2, 3, 4, 5, 6, 7];

console.log(R.splitEvery(3, nums)); // [[1, 2, 3], [4, 5, 6], [7]]
console.log(nums);                  // [1, 2, 3, 4, 5, 6, 7]
Try It Yourself

How It Works

  1. First chunk. Ramda copies items 0–2: [1, 2, 3].
  2. Next chunk. It moves forward by 3 and copies [4, 5, 6].
  3. Leftover. Only 7 remains, so the last chunk is the shorter [7].
  4. Nothing changed. Each chunk is a new array; nums is untouched.

Example 2 — Chunk a String (Official Sample)

Strings split into smaller strings — handy for formatting a card number.

Ramda
const card = '4111222233334444';

console.log(R.splitEvery(3, 'foobarbaz'));    // ['foo', 'bar', 'baz']
console.log(R.splitEvery(4, card).join(' ')); // '4111 2222 3333 4444'
Try It Yourself

How It Works

  1. Characters are items. 'foobarbaz' has 9 characters, so groups of 3 fit exactly.
  2. Strings in, strings out. Each chunk is a string like 'foo', not an array of letters.
  3. Card number. 16 digits in groups of 4 give ['4111', '2222', '3333', '4444'].
  4. Join for display. .join(' ') glues the chunks with spaces.

Example 3 — Split Items into Pages

Two items per page; read one page by its position.

Ramda
const items = ['a', 'b', 'c', 'd', 'e'];
const pages = R.splitEvery(2, items);

console.log(pages);        // [['a', 'b'], ['c', 'd'], ['e']]
console.log(pages.length); // 3
console.log(pages[1]);     // ['c', 'd']  (page 2)
Try It Yourself

How It Works

  1. Chunk by page size. R.splitEvery(2, items) builds every page at once.
  2. Count the pages. pages.length is Math.ceil(5 / 2) = 3.
  3. Pick a page. Pages are 0-based in the array, so page 2 is pages[1].
  4. Last page is short. Page 3 holds only ['e'] — render it the same way.

Example 4 — Build Grid Rows in a Pipeline

Turn nine numbers into a 3 × 3 board, one text row per chunk.

Ramda
const toRows = R.pipe(
  R.splitEvery(3),   // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  R.map(R.join(' ')) // ['1 2 3', '4 5 6', '7 8 9']
);

const rows = toRows([1, 2, 3, 4, 5, 6, 7, 8, 9]);

console.log(rows);            // ['1 2 3', '4 5 6', '7 8 9']
console.log(rows.join('\n')); // one row per line
Try It Yourself

How It Works

  1. Curried size. R.splitEvery(3) waits for a list, so it drops straight into R.pipe.
  2. Make rows. Nine numbers become three chunks of three.
  3. Format each row. R.map runs R.join(' ') on every chunk.
  4. Print the board. Joining the rows with a line break shows the grid.

Example 5 — Total Each Batch, Then Undo the Chunks

Sum sales in groups of three, then flatten the groups back.

Ramda
const sales = [5, 3, 8, 2, 6, 4, 7];
const batches = R.splitEvery(3, sales);

console.log(batches);               // [[5, 3, 8], [2, 6, 4], [7]]
console.log(R.map(R.sum, batches)); // [16, 12, 7]
console.log(R.unnest(batches));     // [5, 3, 8, 2, 6, 4, 7]
Try It Yourself

How It Works

  1. Chunk. Seven sales in groups of 3 give two full batches and [7].
  2. Total each batch. R.map(R.sum) adds up every chunk: 5 + 3 + 8 = 16, 2 + 6 + 4 = 12, 7.
  3. Undo. R.unnest removes one level of nesting and restores the original order.
  4. Safe to reverse. Chunking never drops or reorders items, so unnest always gives back an equal list.

Browser & Runtime Support

R.splitEvery() is plain JavaScript inside Ramda 0.16.0+. It loops over R.slice, which calls the built-in slice that arrays and strings have had since ES3, so support depends only on loading Ramda.

✓ Ramda 0.16.0+ · Any JS runtime

Ramda.js R.splitEvery()

The UMD build (ramda.min.js) uses ES5 syntax, so it runs in every modern browser. Via npm it works in Node.js, Deno, and Bun with require or import.

100% With Ramda loaded
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer End of life · ES5 build may load, untested
Legacy only
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Node.js Supported · npm install ramda
Supported
Deno Supported · npm:ramda
Supported
Bun Supported · bun add ramda
Supported
R.splitEvery() Universal

Bottom line: Safe in any project that loads Ramda 0.16.0 or later. Use ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. The Try-it labs load [email protected] and use modern syntax (const, arrow functions).

Frequently Asked Questions

An array of chunks, each of length n except possibly the last. R.splitEvery(3, [1, 2, 3, 4, 5, 6, 7]) returns [[1, 2, 3], [4, 5, 6], [7]]. A string gives an array of strings: R.splitEvery(3, 'foobarbaz') returns ['foo', 'bar', 'baz'].
They become a shorter last chunk. Nothing is dropped and nothing is padded. Seven items in groups of 3 give two full chunks and a last chunk of [7]. The number of chunks is Math.ceil(length / n).
If n is 0 or negative, R.splitEvery throws an Error: 'First argument to splitEvery must be a positive integer'. If n is larger than the list, you get one chunk holding a copy of everything. An empty list or string returns [].
R.splitEvery(n, list) makes many chunks that do not overlap. R.splitAt(n, list) makes exactly one cut and returns two parts. R.aperture(n, list) makes sliding windows that overlap: R.aperture(3, [1, 2, 3, 4, 5]) is [[1, 2, 3], [2, 3, 4], [3, 4, 5]].
Use R.unnest (or R.flatten for deeper nesting). R.unnest(R.splitEvery(3, list)) gives back a list equal to the original. For string chunks, use chunks.join('').
No. R.splitEvery has been a stable Ramda List function since v0.16.0. It is not deprecated, experimental, or non-standard. Plain JavaScript arrays have no built-in chunk method, which is why helpers like this exist.

Next: R.splitWhen()

Cut a list once, right before the first item that passes a test.

R.splitWhen() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful