Skip to content

Latest commit

 

History

History
62 lines (51 loc) · 1.49 KB

File metadata and controls

62 lines (51 loc) · 1.49 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs ms.assetid caps.latest.revision author ms.author manager
Array.of Function (Array) (JavaScript) | Microsoft Docs
01/18/2017
windows-client-threshold
devlang-javascript
language-reference
JavaScript
TypeScript
DHTML
2884dda3-65d1-4990-9afe-87865c2d4f7f
3
mikejo5000
mikejo
ghogen

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

[!INCLUDEjsv12]