Ramda.js R.prepend() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.prepend(item, list) returns a new list with item added at the front. The original list is never changed (official Ramda docs).

Stable since v0.1.0: R.prepend is not deprecated, experimental, or non-standard. Its mirror is R.append.

Syntax

Call R.prepend. Start with this line.

Ramda
R.prepend(item, list)
CallWhat it does
R.prepend(item, list)Primary signature.
R.prepend(...)Call the list helper.

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

Library declarations
Ramda
R.prepend(item, list)

Parameters

ParameterDescription
itemRequired. Any value. Becomes index 0 of the new list
listRequired. Array. Copied after the item; never changed

Return Value

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

Ramda Examples

Example 1 — Official Sample

Put 'fee' in front of the rest of the giant’s chant.

Ramda
const chant = R.prepend('fee', ['fi', 'fo', 'fum']);

console.log(chant); // ["fee","fi","fo","fum"]
Try It Yourself

How It Works

  1. Item. 'fee' is the value to add.
  2. List. ['fi', 'fo', 'fum'] is copied after it.
  3. Result. A new 4-item array with 'fee' at index 0.

Example 2 — The Original List Stays the Same

Unlike unshift, R.prepend never edits the array you pass in.

Ramda
const nums = [2, 3];
const more = R.prepend(1, nums);

console.log(nums);          // [2, 3]
console.log(more);          // [1, 2, 3]
console.log(nums === more); // false
Try It Yourself

How It Works

  1. New array. R.prepend(1, nums) builds [1, 2, 3] as a fresh array.
  2. Untouched. nums is still [2, 3].
  3. Different objects. nums === more is false, which makes changes easy to detect (e.g. in React state).

Example 3 — A Reusable addZero

Give only the item to get a function you can reuse on any list.

Ramda
const addZero = R.prepend(0);

console.log(addZero([1, 2])); // [0, 1, 2]
console.log(addZero([]));     // [0]
Try It Yourself

How It Works

  1. Curried. R.prepend(0) has the item but no list, so it returns a function.
  2. First call. addZero([1, 2]) → [0, 1, 2].
  3. Empty list. addZero([]) → [0]; an empty list is fine.
  4. Pipelines. Because it waits for the list, addZero fits straight into R.pipe.

Example 4 — R.prepend vs R.concat

Prepending an array nests it. To merge two lists, use R.concat.

Ramda
console.log(R.prepend([1, 2], [3, 4])); // [[1,2],3,4]
console.log(R.concat([1, 2], [3, 4]));  // [1,2,3,4]
Try It Yourself

How It Works

  1. prepend. The whole array [1, 2] becomes one item → 3 items total.
  2. concat. R.concat spreads both lists into one → 4 items.
  3. Rule. One value at the front → prepend. Many values → concat.

Example 5 — Add a Header Row to a Table

A practical use: put column names in front of data rows before printing.

Ramda
const rows = [['Ada', 36], ['Linus', 28]];

const table = R.prepend(['Name', 'Age'], rows);

table.forEach((row) => console.log(row.join(' | ')));
// Name | Age
// Ada | 36
// Linus | 28
Try It Yourself

How It Works

  1. Rows. Each row is an array: ['Ada', 36], ['Linus', 28].
  2. Header. Here nesting is what we want: ['Name', 'Age'] becomes row 0.
  3. Print. row.join(' | ') turns each row into one line of text.

Browser & Runtime Support

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

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.prepend()

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.prepend() 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.prepend(item, list) returns a new list with item added at the front. The original list is not changed.
R.prepend('fee', ['fi', 'fo', 'fum']) returns ['fee', 'fi', 'fo', 'fum'].
unshift changes the original array and returns its new length. R.prepend leaves the original alone and returns a new array.
It is added as one nested item: R.prepend([1, 2], [3, 4]) returns [[1, 2], 3, 4]. Use R.concat([1, 2], [3, 4]) to merge into [1, 2, 3, 4].
R.prepend adds the item at the start of the list; R.append adds it at the end. Both return a new list.
No. R.prepend has been part of Ramda since v0.1.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.range()

Create a list of numbers from a start up to (not including) an end.

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