Maximum number of items in Javascript array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luke

    Maximum number of items in Javascript array

    Does anyone know what the maximum number of items (or characters) allowed
    is, in a javascript array?

    Luke
    (I also posted this in alt.www.webmaster so sorry for the duplication)


  • Martin Honnen

    #2
    Re: Maximum number of items in Javascript array



    Luke wrote:
    [color=blue]
    > Does anyone know what the maximum number of items (or characters) allowed
    > is, in a javascript array?[/color]

    An array in JavaScript can have 0..(2^32-1) elements. 2^32-1 is
    4,294,967,295.

    --

    Martin Honnen


    Comment

    • Luke

      #3
      Re: Maximum number of items in Javascript array

      > An array in JavaScript can have 0..(2^32-1) elements. 2^32-1 is[color=blue]
      > 4,294,967,295.[/color]

      The array I am using is as follows:

      new Array( GetMil(new Date(1992,04,05 )), GetMil(new Date(1992,08,22 )),
      GetMil(new Date(1992,09,16 )) etc. which is a set of these date functions and
      about 1300 characters

      It uses 44 new Date() functions and it had stopped working, however when I
      change the dates to 92 instead if 1992 to reduce the number of characters it
      starts working again.

      Anyone else got any ideas?



      Comment

      • Randy Webb

        #4
        Re: Maximum number of items in Javascript array

        Luke wrote:[color=blue][color=green]
        >>An array in JavaScript can have 0..(2^32-1) elements. 2^32-1 is
        >>4,294,967,295 .[/color]
        >
        >
        > The array I am using is as follows:
        >
        > new Array( GetMil(new Date(1992,04,05 )), GetMil(new Date(1992,08,22 )),
        > GetMil(new Date(1992,09,16 )) etc. which is a set of these date functions and
        > about 1300 characters
        >
        > It uses 44 new Date() functions and it had stopped working, however when I
        > change the dates to 92 instead if 1992 to reduce the number of characters it
        > starts working again.
        >
        > Anyone else got any ideas?[/color]

        I have had, in the past, an array that had 34,000+ entries, each being
        approximately 80 characters in length. Javascript had no problems with
        it. In fact, PHP had more trouble with it than JS did.

        First, define "stopped working". Does it not do what it should, does it
        crash the browser, lock up the browser, just hang, or what?

        What does the GetMil function do? It could very well be that with the
        added overhead, it becomes too many things for the browser to handle
        (due to overload, RAM, etc...) and it stops execution.

        To find out if its the GetMil function, hard code the 44 entries and
        work your way backwards until you find the culprit.



        --
        Randy
        Chance Favors The Prepared Mind
        comp.lang.javas cript FAQ - http://jibbering.com/faq/

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Maximum number of items in Javascript array

          "Luke" <growler8@hotma il.com> writes:
          [color=blue]
          > The array I am using is as follows:
          >
          > new Array( GetMil(new Date(1992,04,05 )), GetMil(new Date(1992,08,22 )),
          > GetMil(new Date(1992,09,16 )) etc. which is a set of these date functions and
          > about 1300 characters
          >
          > It uses 44 new Date() functions and it had stopped working, however when I
          > change the dates to 92 instead if 1992 to reduce the number of characters it
          > starts working again.[/color]

          That suggests that the problem is not the number of entries in the array,
          but the length of the expression.
          Are all dates on the same line (that is, a 1300 char line)? If so, try
          breaking it up on several lines.

          Otherwise, if there is any system to the dates, you can create the array
          programmaticall y with a loop.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          Working...