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
javascript arrays ecmascript-6 syntactic-sugar


source to share


No one has answered this question yet

See similar questions:

18
Array.of vs "[]". When to use Array.of over "[]"?
3
What's the use case for Javascript (ES6) Array.of ()?

or similar:

7287
What does "use strict" do in JavaScript, and what are the reasons for it?
1498
What is the purpose of the var keyword and when should I use it (or omit it)?
1388
What is the purpose of Node.js module.exports and how do you use it?
1153
What does the exclamation mark do in front of the function?
1124
What does "javascript: void (0)" mean?
643
What does% w (array) mean?
478
What does jQuery.fn mean?
463
What is the purpose of the "no-js" HTML class?
398
What is the purpose of backbone.js?
140
Is there a literal notation for a character array?



All Articles
Loading...
X
Show
Funny
Dev
Pics