JavaScript(JS) array method - of

https:/‮www/‬.theitroad.com

The of() method is a static method that creates a new JavaScript array with a variable number of arguments passed to it. It is similar to the Array() constructor, but with of() you don't need to use the new keyword.

Here's an example of how to use the of() method:

let numbers = Array.of(1, 2, 3, 4, 5);

console.log(numbers); // [1, 2, 3, 4, 5]

In this example, we use the of() method to create a new array numbers with the values [1, 2, 3, 4, 5]. We pass the values as arguments to the of() method, and it creates a new array with those values.

The of() method is useful when you want to create a new array with a specific set of values without having to use the Array() constructor and pass an array-like object or an iterable to it.