Array constructor is brittle due to its special-case behavior on single numeric arguments; this is the rationale behind a simpler, more uniform factory function for creating arrays (
There are many array-like objects in JS (
arguments objects, DOM NodeLists, arrays from separate windows, typed arrays) and no simple way to convert one of these to an instance of
Array in the current window; this is the rationale behind a simple conversion function (
Array.from: takes a single argument
x, iterates from 0 to
x.length - 1, and copies the property at each index into a fresh array object.
Array.of: takes a variable number of arguments and produces an instance of
Arraycontaining those elements.
Arrayand does it return a new
SubArrayor a new
ofand the use of
Set.ofwould be better used as conversions from iterables:
Set.of([1, 2, 3, 4, 5]); Array.of(myset);