Ramda.js R.range() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.range(from, to) returns a list of whole numbers that starts at from and stops before to (official Ramda docs).

Stable since v0.1.0: R.range is not deprecated, experimental, or non-standard. Warning: the end number is excluded.

Syntax

Call R.range. Start with this line.

Ramda
R.range(from, to)
CallWhat it does
R.range(from, to)Primary signature.
R.range(...)Call the list helper.

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

Library declarations
Ramda
R.range(from, to)

Parameters

ParameterDescription
fromRequired. Whole number. First value (included)
toRequired. Whole number. Stop value (excluded)

Return Value

Return ValueDescription
*The value returned by R.range().

Ramda Examples

Example 1 — Official Sample

The two calls from the Ramda docs.

Ramda
console.log(R.range(1, 5));   // [1, 2, 3, 4]
console.log(R.range(50, 53)); // [50, 51, 52]
Try It Yourself

How It Works

  1. Start included. Both lists begin with from: 1 and 50.
  2. End excluded. They stop one before to: at 4 and 52.
  3. Length. 5 - 1 = 4 items and 53 - 50 = 3 items.

Example 2 — Include the End Number

Want 1 to 5 with 5? Add one to the end.

Ramda
const upTo = (n) => R.range(1, n + 1);

console.log(upTo(5)); // [1, 2, 3, 4, 5]
console.log(upTo(1)); // [1]
Try It Yourself

How It Works

  1. Shift the end. upTo(5) calls R.range(1, 6).
  2. Stop before 6. The list ends at 5 → [1, 2, 3, 4, 5].
  3. Smallest case. upTo(1) is R.range(1, 2) → [1].

Example 3 — Squares with R.map

Build the numbers first, then transform each one.

Ramda
const squares = R.map((n) => n * n, R.range(1, 6));

console.log(squares); // [1, 4, 9, 16, 25]
Try It Yourself

How It Works

  1. Range. R.range(1, 6) → [1, 2, 3, 4, 5].
  2. Map. R.map runs n * n on each number.
  3. Result. 1×1, 2×2, … 5×5 → [1, 4, 9, 16, 25].

Example 4 — Sum 1 to 100

A classic: add every number from 1 to 100.

Ramda
const total = R.sum(R.range(1, 101));

console.log(total); // 5050
Try It Yourself

How It Works

  1. 101, not 100. The end is excluded, so R.range(1, 101) gives 1 through 100.
  2. Sum. R.sum adds all 100 numbers.
  3. Check. The formula 100 × 101 / 2 also gives 5050.

Example 5 — Page Labels for Pagination

Turn a page count into button labels.

Ramda
const totalPages = 3;

const labels = R.map((p) => 'Page ' + p, R.range(1, totalPages + 1));

console.log(labels.join(' | ')); // Page 1 | Page 2 | Page 3
Try It Yourself

How It Works

  1. Numbers. R.range(1, 3 + 1) → [1, 2, 3] (pages start at 1, not 0).
  2. Labels. R.map turns each number into 'Page 1', 'Page 2', 'Page 3'.
  3. Print. join(' | ') puts them on one line.

Browser & Runtime Support

R.range() is plain JavaScript inside Ramda 0.1.0+. No special browser API is needed.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.range()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge, and in Node.js, Deno, and Bun.

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 No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.range() Universal

Bottom line: Safe in any project that includes Ramda (check with npm ls ramda). Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. These labs load [email protected].

Frequently Asked Questions

R.range(from, to) returns a list of whole numbers starting at from and stopping before to. For example, R.range(1, 5) returns [1, 2, 3, 4].
R.range(1, 5) returns [1, 2, 3, 4] and R.range(50, 53) returns [50, 51, 52].
No. The start is included and the end is excluded. To include the end, pass end + 1: R.range(1, 5 + 1) returns [1, 2, 3, 4, 5].
No. If to is not greater than from, the result is []. There is no step argument. Use R.reverse(R.range(1, 6)) to count down and R.map(n => n * 2, R.range(0, 5)) for steps of 2.
Strings throw TypeError: Both arguments to range must be numbers. In Ramda 0.30.1, decimals such as R.range(1.5, 4) throw RangeError: Invalid array length. Use whole numbers.
No. R.range has been part of Ramda since v0.1.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.rebuild()

Continue the Ramda List series.

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