Array.of method

The Array.of method returns a new array from the values specified in the parameter.

Syntax

javascriptlet newArray = Array.of(element, [element, [element...]]);

Example

Let's obtain a new array from a number specified in the parameter:

javascriptlet res = Array.of(1);
console.log(res);

The code execution result:

javascript[1]

Example

Let's get a new array from strings specified in the parameter:

javascriptlet res = Array.of('a', 'b', 'c');
console.log(res);

The code execution result:

javascript['a', 'b', 'c']

See also

  • the Array.from method
    which obtains an array from an array-like object