Possible Duplicate:
What are the best practices to follow when declaring an array in Javascript?
Would be correct don’t use new Array after of defining a variable using []?
var v = [];
v = Array(5); // is new necessary?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are creating two
Arrayobjects and throwing away one, so what you are doing is not necessary.Declare the variable and create an array:
Or as a single statement:
The preferred way of creating arrays is using
new Arraywhen you want to specify a size, and an array literal when you want to create an array from items:For a zero size array you can use either:
The
Arrayconstructor can also take a list of items, but that use should be avoided because it behaves differently if there is one item and that item is numerical: