Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • X
  • Bluesky
  • GitHub
  • Forum
Language Manual
Overview
  • Introduction
  • Installation
  • Editor Plugins
  • Migrate to ReScript Syntax
  • Try
Language Features
  • Overview
  • Let Binding
  • Type
  • Primitive Types
  • Tuple
  • Record
  • Object
  • Variant
  • Null, Undefined and Option
  • Array & List
    • Array
    • List
  • Function
  • If-Else & Loops
  • Pipe
  • Pattern Matching / Destructuring
  • Mutation
  • JSX
  • Exception
  • Lazy Values
  • Promise
  • Module
  • Import & Export
  • Reserved Keyword
JavaScript Interop
  • Embed Raw JavaScript
  • Shared Data Types
  • External (Bind to Any JS Library)
  • Bind to JS Object
  • Bind to JS Function
  • Import from / Export to JS
  • Bind to Global JS Values
  • JSON
  • Use Illegal Identifier Names
  • Generate Converters & Helpers
  • Browser Support & Polyfills
  • Interop Cheatsheet
Build System
  • Build System Overview
  • Build System Configuration
  • Interop with JS Build Systems
  • Build Performance
Guides
  • Converting from JS
  • Libraries
Extra
  • Newcomer Examples
  • Project Structure
  • FAQ
Docs / Language Manual / Array & List
Edit

You are currently looking at the v6.0 - v8.2 docs (Reason v3.6 syntax edition). You can find the latest manual page here.

(These docs are equivalent to the old BuckleScript docs before the ReScript rebrand)

Array and List

Array

Arrays are our main ordered data structure. They work the same way as JavaScript arrays: they can be randomly accessed, dynamically resized, updated, etc.

Reason (Old Syntax)ML (Older Syntax)JS Output
let myArray = [|"hello", "world", "how are you"|];

ReScript arrays' items must have the same type, i.e. homogeneous.

Usage

See the Js.Array API.

Access & update an array item like so:

Reason (Old Syntax)ML (Older Syntax)JS Output
let myArray = [|"hello", "world", "how are you"|];

let firstItem = myArray[0]; // "hello"

myArray[0] = "hey"; // now [|"hey", "world", "how are you"|]

let pushedValue = Js.Array2.push(myArray, "bye");

List

ReScript provides a singly linked list too. Lists are:

  • immutable

  • fast at prepending items

  • fast at getting the tail

  • slow at everything else

Reason (Old Syntax)ML (Older Syntax)JS Output
let myList = [1, 2, 3];

Like arrays, lists' items need to be of the same type.

Usage

You'd use list for its resizability, its fast prepend (adding at the head), and its fast split, all of which are immutable and relatively efficient.

Do not use list if you need to randomly access an item or insert at non-head position. Your code would end up obtuse and/or slow.

The standard lib provides a List module.

Immutable Prepend

Use the spread syntax:

Reason (Old Syntax)ML (Older Syntax)JS Output
let myList = [1, 2, 3];
let anotherList = [0, ...myList];

myList didn't mutate. anotherList is now [0, 1, 2, 3]. This is efficient (constant time, not linear). anotherList's last 3 elements are shared with myList!

Note that [a, ...b, ...c] is a syntax error. We don't support multiple spread for a list. That'd be an accidental linear operation (O(b)), since each item of b would be one-by-one added to the head of c. You can use List.concat for this, but we highly discourage it.

Updating an arbitrary item in the middle of a list is also discouraged, since its performance and allocation overhead would be linear (O(n)).

Access

switch (described in the pattern matching section) is usually used to access list items:

Reason (Old Syntax)ML (Older Syntax)JS Output
let message =
  switch myList {
  | [] => "This list is empty"
  | [a, ...rest] => "The head of the list is the string " ++ Js.Int.toString(a)
  };
Null, Undefined and OptionFunction

© 2025 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on