JavaScript of()
The of()
method is a static method of the built-in Array
object in JavaScript. It creates a new Array
instance with a variable number of arguments. It accepts any data type as its arguments and allows you to create an array from those arguments.
Syntax
The syntax for of()
method is:
Array.of(element0[, element1[, ..., elementN]])
Example
const myArray = Array.of(1, 'two', false);
console.log(myArray); // Output: [1, "two", false]
Output
In the above example, the of()
method creates a new array instance and initializes it with three elements: the number 1
, the string 'two'
, and the boolean value false
. The output will be [1, "two", false]
.