ES6 - Array.of


Advertisements

This function creates a new array instance from a variable number of arguments, regardless of number or type of the arguments.

Syntax

The syntax mentioned below is for the array method of(), where, elementN are Elements of which to create the array.

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

Example

<script>
   //Array.of
   console.log(Array.of(10))
   console.log(Array.of(10,20,30))
   console.log(Array(3))
   console.log(Array(10,20,30))

</script>

The output of the above code will be as shown below −

[10]
[10, 20, 30]
[empty × 3]
[10, 20, 30]
Advertisements