What purpose does Array.of () serve so that an array literal cannot be anymore?

Array.of()

The static method, a new addition to the JavaScript specification supplied inside ECMAScript 2015, allows you to create an array with whatever arguments are passed to them. For example,

const exampleArr = Array.of(13, 'Test', null, 17 / 2.5, true);
// => [13, "Test", null, 6.8, true]

      

That's all well and good, but what purpose does this method clearly serve? Most of ES6 falls under the banner syntactic sugar , but it doesn't really apply to method Array.of()

, given that we "always had massive literals (i.e. []

) available to us. In other words, are there specific / unique scripts, to which method applies that are not equally well served by a regular array literal?

+3


source to share





All Articles