0

For example,

let x = [1,2,3,5];

is equivalent to:

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

(Unless I'm missing an important detail, which is why I'm asking the question)

You could also mix these with spread ... syntax and variables and thus other arrays. To me, it seems Array.of() has more overhead. Would Array.of() have to parse an arguments object into another array?

I know there's also new Array() as others have before questioned here, but that has a different semantic purpose, so I don't see this question as a duplicate to that.

As I see it now, Array.of() and [ ] seem redundant. The function's intent does seem more explicit on the former, but the latter's intent is simple enough to not be misunderstood.

So to summarize:

  • When is one preferable over the other?
  • Why does Array.of() exist when JavaScript survived without it for so long?
  • And, what're the differences of these two methods, if any? Would there be any needless overhead?
  • I link that post in my question for reference. –  Oct 29 '18 at 14:00
  • If you don't consider your question a duplicate you might simplify to ask a clearly different question. As it is you're covering some of the same ground, I think. – isherwood Oct 29 '18 at 14:04
  • 1
    One of the links now is a rightful duplicate. I did search across Google and here somewhat extensively but could not find one. Sorry, all! I guess engines don't like brackets. –  Oct 29 '18 at 14:06

0 Answers0