What benefit do you get in javascript declaring an array with a specific length?

In most javascript applications, I usually declare such an array

var x = []; 

but I saw a ton of example code on MDN that uses this approach

 var x = new Array(10); 

With V8 / other modern JS engines, do you see real benefits anyway?

+6
source share
1 answer

Is absent. Javascript does not implement real arrays. All this is abstracted out through javascript object notation.

So say:

 a = [0, 1]; b = {"0": 1, "1": 1}; 

Has the same effect:

 a[0] //0 b[0] //0 

Another thing to keep in mind is when you do:

 a[100] = 100; 

The length is automatically set to 101. Although:

 a[2] //undefined 
+2
source

All Articles