Ramda.js R.take() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.take(n, list) returns the first n items of a list, or the first n characters of a string (official Ramda docs). It never changes the original, never throws when n is too big, and R.take(n) is a reusable function for pipelines.

Stable since v0.1.0: R.take is not deprecated, experimental, or non-standard. It is close to native Array.prototype.slice(0, n) and String.prototype.slice(0, n), except that a negative n takes everything.

Syntax

Call R.take. Start with this line.

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

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

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

Parameters

ParameterDescription
nRequired. Number. How many items to keep from the start
listOptional. Array or String. The value to copy from; omit it to get a reusable function

Return Value

Return ValueDescription
*Array → new array, string → new string

Ramda Examples

Example 1 — Lists and Strings (Official Samples)

Keep the first one, two, or more items — or the first characters of a string.

Ramda
const names = ['foo', 'bar', 'baz'];

console.log(R.take(1, names));   // ['foo']
console.log(R.take(2, names));   // ['foo', 'bar']
console.log(R.take(4, names));   // ['foo', 'bar', 'baz']
console.log(R.take(3, 'ramda')); // 'ram'
Try It Yourself

How It Works

  1. One. R.take(1, names) keeps only index 0, still inside an array.
  2. Two. R.take(2, names) keeps indexes 0 and 1.
  3. Too many. Asking for 4 of 3 items returns all three — no error, no undefined.
  4. String. For text, the first 3 characters come back as a string: 'ram'.

Example 2 — Top Three Scores

Sort from high to low, then take the first three.

Ramda
const scores = [70, 95, 88, 60, 99];

const topThree = R.pipe(R.sort(R.descend(R.identity)), R.take(3));

console.log(topThree(scores)); // [99, 95, 88]
Try It Yourself

How It Works

  1. Sort. R.sort with R.descend(R.identity) orders the numbers from highest to lowest: [99, 95, 88, 70, 60].
  2. Take. R.take(3) keeps the first three of that sorted copy.
  3. Pipe. R.pipe runs both steps left to right as one reusable function.
  4. No mutation. Both steps return copies, so scores keeps its original order.

Example 3 — Simple Pagination with drop + take

Skip the earlier pages, then take one page of items.

Ramda
const items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
const page = (n, size) => R.pipe(R.drop((n - 1) * size), R.take(size));

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

How It Works

  1. Skip. For page 2 of size 3, R.drop(3) removes the first page.
  2. Take. R.take(3) keeps the next three items: ['d', 'e', 'f'].
  3. Last page. Only 'g' is left, and take returns it without complaining.
  4. Reusable. page(n, size) builds a function you can apply to any list.

Example 4 — Short Text Excerpt

Cut long text to 11 characters and add dots only when something was removed.

Ramda
const excerpt = (s) => s.length > 11 ? R.take(11, s) + '...' : s;

console.log(excerpt('Ramda makes coding fun')); // 'Ramda makes...'
console.log(excerpt('Short text'));             // 'Short text'
Try It Yourself

How It Works

  1. Check length. 'Ramda makes coding fun' has 22 characters, more than 11.
  2. Take. R.take(11, s) returns the string 'Ramda makes'.
  3. Add dots. '...' tells the reader the text was cut.
  4. Short text. 'Short text' (10 characters) is returned as it is.

Example 5 — Stop Early in a Transducer

Used inside R.into, take stops the work after n items.

Ramda
let calls = 0;
const double = (x) => { calls++; return x * 2; };

const xf = R.compose(R.map(double), R.take(2));

console.log(R.into([], xf, [1, 2, 3, 4, 5])); // [2, 4]
console.log(calls);                           // 2
Try It Yourself

How It Works

  1. Build a transducer. R.compose of R.map and R.take describes the steps; in transducers they run left to right.
  2. Run it. R.into([], xf, list) feeds items one by one into a new array.
  3. Stop. After the second item, take(2) signals “done”, so 3, 4, and 5 are never doubled.
  4. Proof. calls is 2. A plain R.take(2, R.map(double, list)) would call double 5 times.

Browser & Runtime Support

R.take() is plain JavaScript inside Ramda and has existed since v0.1.0. It uses only slice, so support depends only on loading Ramda.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.take()

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.take() Universal

Bottom line: Safe in any project that loads Ramda. 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

A new list with the first n items, or a new string with the first n characters. R.take(2, ['foo', 'bar', 'baz']) returns ['foo', 'bar'] and R.take(3, 'ramda') returns 'ram'. The original is not changed.
You get the whole list as a copy, with no error and no padding. R.take(4, ['foo', 'bar', 'baz']) returns all three items.
It takes everything. R.take(-1, [1, 2, 3]) returns [1, 2, 3]. This is different from [1, 2, 3].slice(0, -1), which returns [1, 2]. To drop the last items use R.dropLast or R.init.
R.take(n, list) is like list.slice(0, n), but it is curried (R.take(5) is a reusable function), works the same on strings, can be used as a transducer, and treats a negative n as 'take everything'.
Yes, as a transducer. In R.into([], R.compose(R.map(f), R.take(2)), list), f runs only for the first two items. A plain R.take(2, R.map(f, list)) runs f on every item first.
No. R.take has been part of Ramda since v0.1.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.takeLast()

Keep the last n items of a list or string.

R.takeLast() 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