On this page
  1. Array.from
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

Array.from

Prev: toSorted | Up: Array | Next: isArray
Rel: Array, Array & Typed Arrays Guide
Ref: MDN Web Docs — Array.from
Tags: #public #web #javascript #builtins #array #tier/standard


Signature & Overview

Array.from(iterableOrArrayLike, mapFn?)

Creates a shallow-copied Array from any iterable (Set, NodeList, string) or array-like { length }.

Notes & Pitfalls

Example

const range = Array.from({ length: 4 }, (_, i) => i * 10);
const unique = Array.from(new Set([1, 2, 2, 3]));
console.assert(JSON.stringify(range) === "[0,10,20,30]");
console.assert(JSON.stringify(unique) === "[1,2,3]");

Linked from

Related notes