Ramda.js R.update() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.update(index, value, list) returns a new array with the item at index replaced by value. Every other item stays where it is, and the original list is left untouched (official Ramda docs).

Stable since v0.14.0: R.update is not deprecated, experimental, or non-standard. It replaces one item by position and never changes the input array.

Syntax

Call R.update. Start with this line.

Ramda
R.update(index, value, list) or R.update(index, value)(list)
CallWhat it does
R.update(index, value, list) or R.update(index, value)(list)Primary signature.
R.update(...)Call the list helper.

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

Library declarations
Ramda
R.update(index, value, list) or R.update(index, value)(list)

Parameters

ParameterDescription
indexRequired. Position to replace; -1 is the last item
valueRequired. The item to store at that position (any type)
listOptional. The array to copy; omit it to get a reusable function

Return Value

Return ValueDescription
*A new array with one slot replaced, or the original list if the index is out of range

Ramda Examples

Example 1 — Official: Replace by Index

The two samples from the Ramda docs: replace index 1, then replace the last item with -1.

Ramda
console.log(R.update(1, '_', ['a', 'b', 'c']));   // ['a', '_', 'c']
console.log(R.update(-1, '_', ['a', 'b', 'c']));  // ['a', 'b', '_']
Try It Yourself

How It Works

  1. Index 1. Indexes start at 0, so index 1 is 'b'.
  2. Replace. R.update copies the list and puts '_' in that slot.
  3. Index -1. A negative index counts from the end, so -1 is 'c'.
  4. Result. Only one slot changes each time; the length stays 3.

Example 2 — Fix One Score, Keep the Original

Correct one value and confirm the input array is unchanged.

Ramda
const scores = [70, 85, 90];
const fixed = R.update(1, 88, scores);

console.log(fixed);            // [70, 88, 90]
console.log(scores);           // [70, 85, 90]
console.log(fixed === scores); // false
Try It Yourself

How It Works

  1. Position. 85 sits at index 1.
  2. Copy and write. R.update(1, 88, scores) builds a new array with 88 in that slot.
  3. No mutation. scores still holds 85, unlike scores[1] = 88.
  4. New reference. fixed === scores is false, which is what React and Redux use to detect a change.

Example 3 — Out-of-Range Index Returns the Original

An index that does not exist replaces nothing. The list never grows.

Ramda
const letters = ['a', 'b', 'c'];

console.log(R.update(3, '_', letters));             // ['a', 'b', 'c']
console.log(R.update(-4, '_', letters));            // ['a', 'b', 'c']
console.log(R.update(3, '_', letters) === letters); // true
Try It Yourself

How It Works

  1. Valid range. For 3 items, valid indexes are 0 to 2, or -1 to -3.
  2. Too big. 3 is past the end, so nothing is replaced.
  3. Too negative. -4 is before the start, so nothing is replaced either.
  4. Same array. Ramda skips the copy and returns letters itself, so === is true. Native letters.with(3, '_') would throw a RangeError.

Example 4 — Update a Record by Id (Safely)

Find the index first, and only update when something was actually found.

Ramda
const todos = [
  { id: 1, done: false },
  { id: 2, done: false },
  { id: 3, done: false }
];

const markDone = (id, list) => {
  const i = R.findIndex(R.propEq(id, 'id'), list);
  return i === -1 ? list : R.update(i, { ...list[i], done: true }, list);
};

console.log(R.pluck('done', markDone(2, todos)));  // [false, true, false]
console.log(R.pluck('done', markDone(9, todos)));  // [false, false, false]
Try It Yourself

How It Works

  1. Find. R.findIndex with R.propEq(2, 'id') returns 1.
  2. Build the new item. Spread syntax { ...list[i], done: true } copies the old todo and flips done.
  3. Replace. R.update(1, newTodo, list) puts it in slot 1 of a new array.
  4. Guard. For id 9, findIndex returns -1. Without the check, R.update(-1, …) would silently overwrite the last todo.

Example 5 — Reusable Setter in a Pipeline

Leave out the list to get a function, then compose it with other helpers.

Ramda
const setHome = R.update(0, 'Home');
const toBreadcrumb = R.pipe(setHome, R.join(' / '));

console.log(toBreadcrumb(['Start', 'Docs', 'API']));  // Home / Docs / API
console.log(toBreadcrumb(['Index', 'Blog']));         // Home / Blog
Try It Yourself

How It Works

  1. Curry. R.update(0, 'Home') has no list yet, so it returns a function that waits for one.
  2. Replace. In the pipe, the first item ('Start' or 'Index') becomes 'Home'.
  3. Join. R.join(' / ') turns the array into one string.
  4. Reuse. setHome works on any list, whatever its length.

Browser & Runtime Support

R.update() is plain JavaScript inside Ramda 0.14.0+: it copies the array and assigns one slot. Without Ramda, native Array.prototype.with() (ES2023) is the closest match, but it needs Chrome 110+, Firefox 115+, Safari 16+, or Node 20+, and it throws on a bad index.

✓ Ramda 0.14.0+ · Any JS runtime

Ramda.js R.update()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge, including older versions without with(). Via npm it works 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.update() Universal

Bottom line: Safe in any project with 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.update(index, value, list) returns a new array where the item at index is replaced by value. The official sample R.update(1, '_', ['a', 'b', 'c']) returns ['a', '_', 'c'].
No. For a valid index it copies the list and writes the new value into the copy, so the original array is unchanged. Native assignment such as list[1] = '_' changes the array in place.
Yes. A negative index counts back from the end, so -1 is the last item. R.update(-1, '_', ['a', 'b', 'c']) returns ['a', 'b', '_'].
Nothing is replaced and no error is thrown. If index >= list.length or index < -list.length, Ramda returns the original list itself (the same reference). The list never grows. Native Array.prototype.with() throws a RangeError instead.
R.update puts a ready-made value at the index and ignores the old item. R.adjust(index, fn, list) calls fn with the old item and stores the result. Use update when you already know the new value, adjust when it depends on the old one.
No. R.update has been a stable Ramda list function since v0.14.0. It is not deprecated, experimental, or non-standard.

Next: R.without()

Remove every occurrence of specific values from a list.

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