A JavaScript static method that creates a new Array-like instance from its arguments, avoiding the Array constructor's numeric-argument ambiguity.
Need an array whose only value is a number? Array.of(1) creates an array containing 1. By contrast, new Array(1) creates a sparse array with a hole. Array.of avoids that numeric-argument ambiguity. section 9.2section 9.6
Compare the results
Array.of(1, 2, 3) creates an array containing those three values; Array.of(1) contains the single value 1. Array literals are preferred in most situations, but Array.of is useful when you need an array subclass instance: AwesomeArray.of(1) creates an AwesomeArray containing 1. section 9.2
How Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond covers it
How deep it goes
Explains the numeric-argument quirk, compares results with Array.of and literals, and notes subclass use without exploring implementation internals.
Examples
Compares Array.of(1) with new Array(1), shows multiple supplied values, and uses AwesomeArray.of(1) as a subclass example.
What you can do after
Apply Array.of to create arrays whose numeric arguments are values, including instances of an Array subclass.
How it connects
Contrasts Array.of with the Array constructor and array literals, and connects it to Array subclasses.
arraycontrasts with · An array is an indexed, ordered collection of elements arranged in one or more dimensions, with elements accessed by position.
type-lifting functionkind of · A type-lifting function embeds a value into a corresponding computational context, container, or type, often a monadic type.
This explainer was generated by Manning's knowledge graph from the text of Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond. The section links point to the parts of the book it draws on.