I read some tutorials on arrays on Javascript. They suggest that it is possible to declare an array with a specific length by passing an integer to array constructor using var test = new Array(4); syntax.
I used this syntax and ran through jsLint and ran into these problems
Error: Problem at line 1 character 22: Expected ')' and instead saw '4'.
var test = new Array(4);
Problem at line 1 character 23: Expected ';' and instead saw ')'.
var test = new Array(4);
Problem at line 1 character 23: Expected an identifier and instead saw ')'.
So I have some questions regarding this. Am I running into problem using new Array()? Is this incompatible with browsers of some types?
Also, if I switch into square brackets like this [], is there any way to initialize array and set the length on one line or do I do something like below?
var test = [];
test.length = 4;