Ramda.js R.init() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.init(list) returns every item except the last. On a string, it returns every character except the last (official Ramda docs). It is exactly R.slice(0, -1), and the input is never changed.

Stable since v0.9.0: R.init is not deprecated, experimental, or non-standard. It never mutates: you always get a new array or string.

Syntax

Call R.init. Start with this line.

Ramda
R.init(list)
CallWhat it does
R.init(list)Primary signature.
R.init(...)Call the list helper.

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

Library declarations
Ramda
R.init(list)

Parameters

ParameterDescription
listRequired. Array or String. The input to copy without its last item

Return Value

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

Ramda Examples

Example 1 — Official Array Samples

Drop the last item, down to an empty list.

Ramda
console.log(JSON.stringify(R.init([1, 2, 3]))); // [1,2]
console.log(JSON.stringify(R.init([1])));       // []
console.log(JSON.stringify(R.init([])));        // []
Try It Yourself

How It Works

  1. Three items. The last one, 3, is dropped, leaving [1, 2].
  2. One item. That item is also the last, so nothing is left: [].
  3. Empty list. Nothing to drop; you still get [], not an error.
  4. Printing. JSON.stringify just makes the arrays easy to read.

Example 2 — Official String Samples

On a string, R.init drops the last character and returns a string.

Ramda
console.log(JSON.stringify(R.init('abc'))); // "ab"
console.log(JSON.stringify(R.init('a')));   // ""
console.log(JSON.stringify(R.init('')));    // ""
Try It Yourself

How It Works

  1. String in, string out. Ramda calls the string’s own slice(0, -1).
  2. Drop one character. 'abc' becomes 'ab'.
  3. Short strings. 'a' and '' both give the empty string ''.
  4. Quotes. JSON.stringify shows the quotes so the empty string is visible.

Example 3 — Join a List with “and”

Split the list into “everything but the last” and “the last” to build a readable sentence.

Ramda
const names = ['Ann', 'Bob', 'Cy'];

const sentence = R.join(', ', R.init(names)) + ' and ' + R.last(names);

console.log(sentence); // Ann, Bob and Cy
Try It Yourself

How It Works

  1. Beginning. R.init(names) is ['Ann', 'Bob'].
  2. Join. R.join(', ') turns it into 'Ann, Bob'.
  3. Last. R.last(names) is 'Cy', added after ' and '.
  4. Limit. This assumes two or more names; one name would give ' and Ann', so check the length first.

Example 4 — Remove a Trailing Slash

Combine R.init with R.when to drop the last character only when it is a /.

Ramda
const trimSlash = R.when(R.endsWith('/'), R.init);

console.log(trimSlash('/docs/')); // /docs
console.log(trimSlash('/docs'));  // /docs
Try It Yourself

How It Works

  1. Test. R.endsWith('/') checks the last character.
  2. Transform. If true, R.when runs R.init, dropping the slash.
  3. Otherwise. '/docs' fails the test and is returned unchanged.
  4. Point-free. R.init takes one argument, so it plugs in with no wrapper.

Example 5 — init vs tail vs dropLast

Three similar helpers on the same list.

Ramda
const xs = [1, 2, 3, 4];

console.log(JSON.stringify(R.init(xs)));        // [1,2,3]
console.log(JSON.stringify(R.tail(xs)));        // [2,3,4]
console.log(JSON.stringify(R.dropLast(2, xs))); // [1,2]
Try It Yourself

How It Works

  1. init. Drops the last item: [1, 2, 3].
  2. tail. R.tail drops the first item: [2, 3, 4].
  3. dropLast. R.dropLast(2) drops the last two: [1, 2].
  4. Same idea. R.init(xs) equals R.dropLast(1, xs), and xs itself never changes.

Browser & Runtime Support

R.init() has been in Ramda since v0.9.0. Internally it calls slice(0, -1), which every JavaScript engine has supported since ES3.

✓ Ramda 0.9.0+ · Any JS runtime

Ramda.js R.init()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun with require or import.

100% With Ramda 0.9+ 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.init() Universal

Bottom line: Safe in any project with Ramda 0.9.0 or later. Without Ramda, the native list.slice(0, -1) gives the same result everywhere. These labs load [email protected].

Frequently Asked Questions

R.init(list) returns a new list with every item except the last one. On a string it returns every character except the last. It is the same as R.slice(0, -1, list), and the original is never changed.
R.init drops the last item, R.tail drops the first. On [1, 2, 3], R.init gives [1, 2] and R.tail gives [2, 3].
Both give an empty result: [] for arrays and '' for strings. R.init never throws on empty input and never returns undefined.
Use R.splitAt(-1, list). R.splitAt(-1, [1, 2, 3]) returns [[1, 2], [3]], which is R.init and the last item wrapped in an array.
pop() changes the original array and returns the removed item. R.init leaves the original alone and returns the remaining items, which is safer when the list is shared, for example in React state.
No. R.init has been a stable Ramda List function since v0.9.0. It is not deprecated, experimental, or non-standard.

Next: R.insert()

Add an item at a given position without changing the original list.

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