Ramda.js R.insertAll() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.insertAll(index, items, list) returns a new list with all of items placed at index, in order. It is the many-item version of R.insert, and the original list is not changed (official Ramda docs).

Stable since v0.9.0: R.insertAll is not deprecated, experimental, or non-standard. Note: the items must be an array, and a negative index adds them at the end.

Syntax

Call R.insertAll. Start with this line.

Ramda
R.insertAll(index, items, list)
CallWhat it does
R.insertAll(index, items, list)Primary signature.
R.insertAll(...)Call the list helper.

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

Library declarations
Ramda
R.insertAll(index, items, list)

Parameters

ParameterDescription
indexRequired. Number. Where the new items start (0 = start)
itemsRequired. Array. The items to add, in order
listRequired. Array. The list to copy and insert into

Return Value

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

Ramda Examples

Example 1 — Official Sample

Put three letters at index 2, as in the Ramda docs.

Ramda
const result = R.insertAll(2, ['x', 'y', 'z'], [1, 2, 3, 4]);

console.log(JSON.stringify(result)); // [1,2,"x","y","z",3,4]
Try It Yourself

How It Works

  1. Argument order. Index first, items array second, list last.
  2. Position 2. The item at index 2 is 3, so the letters go just before it.
  3. Order kept. 'x', 'y', 'z' appear in the same order as in the array.
  4. Shift. 3 and 4 move right; the result has 7 items.

Example 2 — The Original List Stays the Same

Fill a gap in a list, then print both the new list and the old one.

Ramda
const letters = ['a', 'd'];
const full = R.insertAll(1, ['b', 'c'], letters);

console.log(JSON.stringify(full));    // ["a","b","c","d"]
console.log(JSON.stringify(letters)); // ["a","d"]
Try It Yourself

How It Works

  1. Cut. At index 1, the list splits into ['a'] and ['d'].
  2. Fill. 'b' and 'c' go into the gap, giving full.
  3. Untouched. letters is still ['a', 'd'].
  4. Compare. Native letters.splice(1, 0, 'b', 'c') would change letters itself.

Example 3 — Insert Before a Known Item

Find a step with R.indexOf, then add two new steps right before it.

Ramda
const steps = ['Mix', 'Bake', 'Serve'];
const i = R.indexOf('Bake', steps);

const updated = R.insertAll(i, ['Grease pan', 'Preheat oven'], steps);

console.log(JSON.stringify(updated));
// ["Mix","Grease pan","Preheat oven","Bake","Serve"]
Try It Yourself

How It Works

  1. Find. R.indexOf('Bake', steps) is 1.
  2. Insert. Both new steps go at index 1, just before 'Bake'.
  3. Order kept. 'Grease pan' comes before 'Preheat oven', as in the array.
  4. Not found? indexOf would return -1, and insertAll would add the steps at the end.

Example 4 — A Reusable “Add Header” Step

Leave out the list to get a function that puts a header row at the top of any CSV lines.

Ramda
const addHeader = R.insertAll(0, ['Name,Age']);

const csv = R.join('\n', addHeader(['Ann,31', 'Bob,27']));

console.log(csv);
// Name,Age
// Ann,31
// Bob,27
Try It Yourself

How It Works

  1. Curry. R.insertAll(0, ['Name,Age']) has its index and items, so it waits for a list.
  2. Insert at 0. The header row goes before the first data row.
  3. Join. R.join('\n') turns the rows into one string, one row per line.
  4. Reuse. Call addHeader on any list of rows, or drop it into R.pipe.

Example 5 — insertAll vs insert vs concat

Three ways to add ['x', 'y'] to [1, 2].

Ramda
const extra = ['x', 'y'];

console.log(JSON.stringify(R.insertAll(1, extra, [1, 2]))); // [1,"x","y",2]
console.log(JSON.stringify(R.insert(1, extra, [1, 2])));    // [1,["x","y"],2]
console.log(JSON.stringify(R.concat([1, 2], extra)));       // [1,2,"x","y"]
Try It Yourself

How It Works

  1. insertAll. Spreads the items at index 1: four flat items.
  2. insert. R.insert treats the array as one item, so it is nested.
  3. concat. R.concat spreads too, but always at the end — no index.
  4. Rule of thumb. Many items at a position → insertAll.

Browser & Runtime Support

R.insertAll() has been in Ramda since v0.9.0. It only uses slice and concat, which every JavaScript engine supports.

✓ Ramda 0.9.0+ · Any JS runtime

Ramda.js R.insertAll()

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

Bottom line: Safe in any project with Ramda 0.9.0 or later. The native non-mutating alternative, list.toSpliced(i, 0, ...items), needs ES2023: Chrome 110+, Firefox 115+, Safari 16+, Node 20+. These labs load [email protected].

Frequently Asked Questions

R.insertAll(index, items, list) returns a new list with every item of the items array placed at index, in order. Items already at that position move right. The original list is never changed.
R.insert adds one value. If that value is an array, it stays nested: R.insert(1, ['x', 'y'], [1, 2]) is [1, ['x', 'y'], 2]. R.insertAll spreads the array: R.insertAll(1, ['x', 'y'], [1, 2]) is [1, 'x', 'y', 2].
The items go at the end. R.insertAll(-1, ['x'], [1, 2, 3]) and R.insertAll(99, ['x'], [1, 2, 3]) both give [1, 2, 3, 'x']. Native splice would treat -1 as before the last item.
No. It builds a new array from a copy of the part before the index, the new items, and a copy of the part after. Neither the list nor the items array is changed.
[...list.slice(0, i), ...items, ...list.slice(i)] works in every modern browser. list.toSpliced(i, 0, ...items) is shorter but needs ES2023 (Chrome 110, Firefox 115, Safari 16, Node 20), and both treat negative indexes differently from Ramda.
No. R.insertAll has been a stable Ramda List function since v0.9.0. It is not deprecated, experimental, or non-standard.

Next: R.intersperse()

Put a separator value between every pair of items.

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