Array.of
Creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments
Syntax
Array.of(...elements)Parameters
| Parameter | Type | Description |
|---|---|---|
| elements | T[] | Elements to put in the array |
Return Value
A new Array instance
Examples
console.log(Array.of(1, 2, 3)); // [1, 2, 3]console.log(Array.of(7)); // [7]
console.log(Array(7)); // [ <7 empty items> ]console.log(Array.of('a', 'b', 'c')); // ['a', 'b', 'c']Understanding Array.of
The Array.of method in JavaScript creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.
The method signature is Array.of(...elements). It accepts 1 parameter: elements. When called, it returns a new array instance. Understanding when and how to use of() helps you write more expressive, readable code.
Common use cases for Array.of include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-from, array-isarray, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Array.of is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More Array Methods
Other methods in the Array object
Related Tools
More Array Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.