JavaScript - Arrays - of

javascript-arrays

// JavaScript - Array.of:

The Array.of() method creates a new Array instance with a variable number of 
arguments, regardless of number or type of the arguments.

The difference between Array.of() and the Array constructor is in the handling 
of integer arguments: Array.of(7) creates an array with a single element, 7, 
whereas Array(7) creates an array with 7 elements, each of which is undefined.

Array.of(7);       // [7] 
Array.of(1, 2, 3); // [1, 2, 3]

Array(7);          // [ , , , , , , ]
Array(1, 2, 3);    // [1, 2, 3]

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

The Array.of method returns an array.  The Array.of method is part of the 
ECMAScript 6 standard.

Array.of(1);         // [1]
Array.of(1, 2, 3);   // [1, 2, 3]
Array.of(undefined); // [undefined]
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License