Loading ...
Sorry, an error occurred while loading the content.

2975Re: Array construction bug

Expand Messages
  • Alexandre Morgaut
    Aug 31, 2012
    • 0 Attachment
      Yes there is a workaround, one that still respect JSLint guidelines

      You can fix the length without the array constructor, even with a dynamic value

      Just do:

      var len = 50;
      var arr = [];
      arr.length = len;

      --- In jslint_com@yahoogroups.com, 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?
      >
    • Show all 21 messages in this topic