re: 10 JavaScript array methods you should know VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION
 

I think it's more likely to compare it to the array constructor. According to MDN

The difference between Array.of() and the Array constructor is in the handling of integer arguments: Array.of(7) creates an array with a single element, 7, whereas Array(7) creates an empty array with a length property of 7 (Note: this implies an array of 7 empty slots, not slots with actual undefined values).

I didn't know this method either!

 
 

He asked about [1, 2, 3, 4, 5, 6] and not Array(7), is it the same?

it is essentially the same, I just pointed out what is a better comparison case with quote from the mdn docs

Your quote from MDN has nothing to do with the question though.
const arr = [7] and const arr = Array.of(7) will give exactly the same resut.

> const arr1 = Array(7);
> const arr2 = [7];
> const arr3 = Array.of(7);

> arr1
[ <7 empty items> ]
> arr2
[ 7 ]
> arr3
[ 7 ]
> 
code of conduct - report abuse