Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


7,823 Points

different ways of creatiing arrays

I saw someone write some arrays differently and I'm curious if there are pros to writing them these ways

/***why would I create an empty array like as opposed to var arry=[];,
 I'm writing more code to achieve the same result, which isnt dry, 
so way would javascript go through the trouble of allowing new to 
be used this way, is there a benefit to writing this way that i'm missing?***/

var arry= new Array();

/***why would I create an empty array like this but specify that 
there are 3 empty indexes?, What benefit of is there of writing this way? 
why create 3 empty indexes instead of using an array method like .unshift()***/

var arry= new Array(3);

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

To be honest, I'm not sure I totally understand all the details regarding writing arrays this way. But from what I can find, it's generally not suggested. When you write an array that way it has to go out to the global constructor and make a new array that way. But some people contend that the processing time of making an array this way is faster in certain browsers depending on the size of the array. Here's the stuff on stackoverflow I found about it. http://stackoverflow.com/questions/931872/what-s-the-difference-between-array-and-while-declaring-a-javascript-ar