Array.from() & Array.of() in JavaScript

From the JavaScript Array Methods cheat sheet ยท Array Creation & Conversion ยท verified Jul 2026

Array.from() & Array.of()

Create arrays from array-like objects or iterables

javascript
// Create array from iterable
Array.from('hello');           // ['h', 'e', 'l', 'l', 'o']
Array.from(new Set([1, 2]));   // [1, 2]

// With mapping function
Array.from({length: 5}, (_, i) => i); // [0, 1, 2, 3, 4]

// Create array from arguments
Array.of(1, 2, 3);    // [1, 2, 3]
Array.of(7);          // [7] (not empty array of length 7)
๐Ÿ’ก Array.from() converts iterables to arrays
โšก Second parameter maps elements during creation
๐Ÿ“Œ Array.of() creates array from arguments
๐Ÿ”— Useful for NodeList, arguments, Set, Map
๐ŸŸข Essential for DOM manipulation

More JavaScript tasks

Back to the full JavaScript Array Methods cheat sheet