Ramda.js R.startsWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.startsWith(prefix, list) returns true when a string or list begins with a given prefix, and false otherwise (official Ramda docs). Lists are compared item by item by value, and R.startsWith(prefix) is a reusable test for R.filter and friends.

Stable since v0.24.0: R.startsWith is not deprecated, experimental, or non-standard. For strings only, JavaScript has the native String.prototype.startsWith(); arrays have no built-in equivalent.

Syntax

Call R.startsWith. Start with this line.

Ramda
R.startsWith(prefix, list) or R.startsWith(prefix)(list)
CallWhat it does
R.startsWith(prefix, list) or R.startsWith(prefix)(list)Primary signature.
R.startsWith(...)Call the list helper.

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

Library declarations
Ramda
R.startsWith(prefix, list) or R.startsWith(prefix)(list)

Parameters

ParameterDescription
prefixRequired. String or Array. What the value should begin with
listOptional. String or Array. The value to check; omit it to get a reusable test

Return Value

Return ValueDescription
*true or false

Ramda Examples

Example 1 — Strings and Lists (Official Samples)

The same function checks a string prefix and a list prefix.

Ramda
console.log(R.startsWith('a', 'abc'));             // true
console.log(R.startsWith('b', 'abc'));             // false
console.log(R.startsWith(['a'], ['a', 'b', 'c'])); // true
console.log(R.startsWith(['b'], ['a', 'b', 'c'])); // false
Try It Yourself

How It Works

  1. String prefix. 'abc' begins with 'a', so the first check is true.
  2. Not at the start. 'b' is inside 'abc' but not first, so it is false.
  3. List prefix. ['a'] matches the first item of ['a', 'b', 'c'].
  4. Brackets matter. For lists the prefix is also a list, even for one item.

Example 2 — Keep Only API URLs

A curried prefix test plugs straight into R.filter.

Ramda
const paths = ['/api/users', '/about', '/api/posts', '/apix'];

const isApi = R.startsWith('/api/');

console.log(R.filter(isApi, paths)); // ['/api/users', '/api/posts']
Try It Yourself

How It Works

  1. Curry the prefix. R.startsWith('/api/') returns a function that waits for a string.
  2. Filter. R.filter keeps every path for which that test is true.
  3. Trailing slash. '/apix' fails because the prefix includes the / after api.
  4. Result. Only the two real API paths remain, in their original order.

Example 3 — Check Path Segments (List Prefix)

Split a file path into folders, then test the first segments as a list.

Ramda
const parts = 'src/lib/util.js'.split('/'); // ['src', 'lib', 'util.js']

console.log(R.startsWith(['src', 'lib'], parts)); // true
console.log(R.startsWith(['src', 'app'], parts)); // false
Try It Yourself

How It Works

  1. Make a list. split('/') turns the path into ['src', 'lib', 'util.js'].
  2. Take two. The prefix has 2 items, so Ramda compares only ['src', 'lib'].
  3. Whole segments. Unlike a string check, ['src', 'li'] would not match 'lib'.
  4. Mismatch. 'app' differs from 'lib', so the second check is false.

Example 4 — Objects Are Compared by Value

Check that a list of steps begins with a login step.

Ramda
const steps = [{ type: 'login' }, { type: 'view' }, { type: 'buy' }];

console.log(R.startsWith([{ type: 'login' }], steps)); // true
console.log(steps[0] === { type: 'login' });           // false
Try It Yourself

How It Works

  1. A new object. { type: 'login' } in the prefix is a different object from steps[0].
  2. Deep comparison. Ramda uses R.equals, which compares the contents, so it matches.
  3. Reference check. === compares identity, so the plain check is false.
  4. Why it helps. You can describe the expected start with literals instead of keeping references.

Example 5 — Case-Insensitive Prefix Check

Lowercase each string first, then test the prefix.

Ramda
const startsWithHi = R.pipe(R.toLower, R.startsWith('hi'));
const greetings = ['Hi there', 'hello', 'HI!', 'ship'];

console.log(R.startsWith('hi', 'Hi there'));    // false
console.log(R.filter(startsWithHi, greetings)); // ['Hi there', 'HI!']
Try It Yourself

How It Works

  1. Case matters. 'H' and 'h' are different, so the plain check is false.
  2. Lowercase first. R.toLower turns 'HI!' into 'hi!' before the test runs.
  3. Combine. R.pipe joins both steps into one reusable test.
  4. Only the start. 'ship' contains 'hi' but does not start with it, so it is dropped.

Browser & Runtime Support

R.startsWith() is plain JavaScript inside Ramda 0.24.0+. It is built on R.take and R.equals, not on the ES2015 String.prototype.startsWith, so support depends only on loading Ramda.

✓ Ramda 0.24.0+ · Any JS runtime

Ramda.js R.startsWith()

The UMD build (ramda.min.js) uses ES5 syntax, so it runs in every modern browser. Via npm it works in Node.js, Deno, and Bun with require or import.

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 End of life · ES5 build may load, untested
Legacy only
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Node.js Supported · npm install ramda
Supported
Deno Supported · npm:ramda
Supported
Bun Supported · bun add ramda
Supported
R.startsWith() Universal

Bottom line: Safe in any project that loads Ramda 0.24.0 or later. Use ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. The Try-it labs load [email protected] and use modern syntax (const).

Frequently Asked Questions

A boolean. R.startsWith(prefix, list) is true when the string or list begins with prefix. R.startsWith('a', 'abc') is true and R.startsWith(['b'], ['a', 'b', 'c']) is false.
The native method works only on strings and is called on the text: 'abc'.startsWith('a'). R.startsWith takes the prefix first, is curried, and also works on arrays, comparing items by value with R.equals. The native method has an optional position argument; Ramda does not.
Yes. R.startsWith('hi', 'Hi there') is false. Lowercase the text first, for example R.pipe(R.toLower, R.startsWith('hi')).
An empty prefix ('' or []) always returns true, even for an empty list. A prefix longer than the list always returns false.
Yes. Items are compared by value, so R.startsWith([{ type: 'login' }], steps) is true when the first step looks like { type: 'login' }, even though it is a different object.
No. R.startsWith has been a stable Ramda List function since v0.24.0. It is not deprecated, experimental, or non-standard.

Next: R.swap()

Swap the positions of two items in a list.

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