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