Whenever I work with arrays, I always use the [] style, however, when I want to create an array with a fixed amount of elements I use new Array(N) (I don’t know any other way of doing this)
I thought it wasn’t big deal, until I read these strong words about this:
Anyone doing this, using “new Array()” instead of “[]“, or “new
Object()” instead of “{}” needs to relearn JavaScript.
I really want to avoid writting bad code. Anyone mind tell me the right direction to go?
I wouldn’t worry too much about some random comment on a blog in 2006. Especially since your use case isn’t just
new Array(). You’re using the special-case constructor that is provided specifically for this purpose.Besides, using
new Array()instead of[]is hardly the worst thing someone can do with JS.