Array() gives you?

Array() gives you?
0

#1
function a(array){
	return Array(array.length);
}

console.log(a(["one","two","three"]))

the above snippet gives me this result:

[ , , ,] a.k.a 3 an array with 3 empty space that is waiting to be filled in.

so Array(3) means make an empty array that has 3 elements inside it, is that correct?


#2

I rarely learn so much from answering a question. My first thought was "he should be calling the Array constructor by using new Array(3). Does his code even work? I tested it, and I couldn’t get it to fail. According to this answer on StackOverflow, calling the Array constructor as a function without new works because it’s in the specification.

So, yes. The following two pieces of code will create an empty array with 3 elements in it:

Array(3);
new Array(3);

#3

thank you. I was doing this tutorial online and could not understand the snippet in it,.


#4

Also, if you could, mark my original reply with the green checkmark to indicate solved, that would be great.


#5

yeah forgot to do that :wink: