Standard built-ins

Array.from()

Try the free JavaScript compiler

Constructs an array from an iterable, preferring its iterator over array-like indexed access. Optional mapper receives value and index. Array-like inputs are read through their length; absent indices produce undefined.

Formal Syntax & Structure

javascript syntaxjavascript
Array.from(source, mapFn?, thisArg?)

Parameters & Attributes

NameTypeDescription
sourceiterable or array-likeSource values.
mapFnfunctionOptional transformation receiving value and index.
thisArganyOptional receiver for mapFn.

Return Value

Array

New array when called as Array.from.

Working Example

Example Snippetjavascript
console.log(Array.from({length:3},(_,i)=>i+1).join(","));
JavaScript Reference