On this page
  1. Array & Typed Arrays
  2. Contents
  3. Functional & Non-Mutating Array Methods
  4. Binary Buffers (ArrayBuffer & TypedArray)

Array & Typed Arrays

Prev: Object & Reflect | Up: builtins | Next: Collections: Map, Set, WeakMap & WeakSet
Rel: Core Syntax & Types
Ref: MDN Web Docs — Array
Tags: #public #web #javascript #builtins


Contents


Functional & Non-Mutating Array Methods

ES2023 added copy-by-default counterparts (toSorted, toReversed, toSpliced, with) alongside map, filter, reduce, flatMap, and .at(-1):

const nums = [3, 1, 4, 1, 5];
const sorted = nums.toSorted((a, b) => a - b); // [1, 1, 3, 4, 5], nums unchanged
const updated = nums.with(0, 9);               // [9, 1, 4, 1, 5]
const last = nums.at(-1);                      // 5

Binary Buffers (ArrayBuffer & TypedArray)

ArrayBuffer allocates raw fixed-length binary memory; typed array views (Uint8Array, Int32Array, Float64Array, DataView) read and write packed numeric values with zero boxing overhead.

const bytes = new Uint8Array([0x48, 0x69]);
const text = new TextDecoder().decode(bytes); // "Hi"

Linked from

Related notes