Array.from() and Array.of()
In addition to array literals, JavaScript provides two static constructor methods for creating arrays from other data sources or from a fixed list of arguments.
Array.from(iterable, mapFn)
Array.from converts any iterable or array-like object into a real array. Array-like objects have numeric indices and a length property but lack array methods — NodeList, arguments, Map, Set, and strings all qualify. An optional second argument works like a map function applied to each element during conversion.
Array.of(...items)
Array.of creates an array from its arguments. Unlike the Array(n) constructor — which creates a sparse array of length n when called with a single number — Array.of(7) creates [7], making its behaviour consistent and predictable.
Creating Ranges
Array.from({ length: n }, (_, i) => i) is the idiomatic way to create a range array without a loop.