Standard built-ins
Array.from()
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
| Name | Type | Description |
|---|---|---|
| source | iterable or array-like | Source values. |
| mapFn | function | Optional transformation receiving value and index. |
| thisArg | any | Optional 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(","));