2975Re: Array construction bug
- Aug 31, 2012Yes there is a workaround, one that still respect JSLint guidelines
You can fix the length without the array constructor, even with a dynamic value
var len = 50;
var arr = ;
arr.length = len;
--- In firstname.lastname@example.org, Martin Cooper <mfncooper@...> wrote:
> If I need to create an array with a specified length, and the length
> is a literal, JSLint is happy enough with this:
> var arr = new Array(50);
> If, however, the value comes from a variable:
> var len = 50,
> arr = new Array(len);
> JSLint complains with an unusable "solution", despite the value being a Number:
> Use the array literal notation .
> Of course, if I use array literal notation, I don't get the semantics I want.
> Seems like a bug to me. Is there a workaround?
- << Previous post in topic Next post in topic >>