Array.of Function (Array) (JavaScript)

Returns an array from the passed in arguments.

Syntax

Array.of(element0[, element1][, ...][,elementN]);  

Parameters

element0,...,elementN
Optional. The elements to place in the array. This creates an array with n + 1 elements, and a length of n + 1.

Remarks

This function is similar to calling new Array(args), but Array.of does not include special behavior when one argument is passed in.

Example

The following example creates an array from passed in numbers.

var arr = Array.of(1, 2, 3);  
// arr[0] == 1   

Example

The following example shows the difference between using Array.of and new Array.

var arr1 = Array.of(3);  
// arr1[0] == 3  

// With new Array, a single argument specifies  
// the length of the new array.  
var arr2 = new Array(3);  
// arr2[0] is undefined  
// arr2.length == 3  

Requirements

Supported in Microsoft Edge (Edge browser). Also supported in Store apps (Microsoft Edge on Windows 10). See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.