Create Dynamic Arrays

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

    Create Dynamic Arrays

    Hi,

    Is there a way in javascript to create Dynamic arrays or arrays on
    fly.
    Something Like:
    var "ptsgN"+sd = new Array();

    Here sd is incrementing by 1.

    I have lots of data that I am putting in arrays.
    I dont have the exact no.
    i dont want to do that:
    var ptsgN1 = new Array();
    var ptsgN2 = new Array();
    var ptsgN3 = new Array();
    var ptsgN4 = new Array();
    .....

    Any Advice.
  • Stevo

    #2
    Re: Create Dynamic Arrays

    Sunny wrote:
    Hi,
    >
    Is there a way in javascript to create Dynamic arrays or arrays on
    fly.
    Something Like:
    var "ptsgN"+sd = new Array();
    >
    Here sd is incrementing by 1.
    >
    I have lots of data that I am putting in arrays.
    I dont have the exact no.
    i dont want to do that:
    var ptsgN1 = new Array();
    var ptsgN2 = new Array();
    var ptsgN3 = new Array();
    var ptsgN4 = new Array();
    ....
    >
    Any Advice.
    This would work:

    for(var i=0;i<9;i++)
    window["ptsgN"+i]=[];

    [] is the same as new Array()

    Comment

    • Grant

      #3
      Re: Create Dynamic Arrays

      On Thu, 16 Oct 2008 12:53:50 -0700 (PDT), Sunny <sunnyluthra1@g mail.comwrote:
      >Hi,
      >
      >Is there a way in javascript to create Dynamic arrays or arrays on
      >fly.
      >Something Like:
      >var "ptsgN"+sd = new Array();
      >
      >Here sd is incrementing by 1.
      >
      >I have lots of data that I am putting in arrays.
      >I dont have the exact no.
      >i dont want to do that:
      >var ptsgN1 = new Array();
      >var ptsgN2 = new Array();
      >var ptsgN3 = new Array();
      >var ptsgN4 = new Array();
      Two dimensional array?

      Grant.
      --

      Comment

      • Sunny

        #4
        Re: Create Dynamic Arrays

        On Oct 16, 4:05 pm, Stevo <n...@mail.inva lidwrote:
        Sunny wrote:
        Hi,
        >
        Is there a way in javascript to create Dynamic arrays or arrays on
        fly.
        Something Like:
        var "ptsgN"+sd = new Array();
        >
        Here sd is incrementing by 1.
        >
        I have lots of data that I am putting in arrays.
        I dont have the exact no.
        i dont want to do that:
        var ptsgN1 = new Array();
        var ptsgN2 = new Array();
        var ptsgN3 = new Array();
        var ptsgN4 = new Array();
        ....
        >
        Any Advice.
        >
        This would work:
        >
        for(var i=0;i<9;i++)
        window["ptsgN"+i]=[];
        >
        [] is the same as new Array()
        Thanks Stevo,
        It worked...

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Create Dynamic Arrays

          Sunny wrote:
          Is there a way in javascript to create Dynamic arrays or arrays on
          fly.
          In ECMAScript implementations , arrays are dynamic by default.
          Something Like:
          var "ptsgN"+sd = new Array();
          >
          Here sd is incrementing by 1.
          Array object references can be elements of arrays.
          [...]
          Any Advice.
          RTFM, finally. (And why not employ a spellchecker before posting?)

          <http://jibbering.com/faq/>


          PointedEars
          --
          Prototype.js was written by people who don't know javascript for people
          who don't know javascript. People who don't know javascript are not
          the best source of advice on designing systems that use javascript.
          -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

          Comment

          Working...