Connecting Tech Pros Worldwide Forums | Help | Site Map

Create Dynamic Arrays

Sunny
Guest
 
Posts: n/a
#1: Oct 16 '08
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
Guest
 
Posts: n/a
#2: Oct 16 '08

re: Create Dynamic Arrays


Sunny wrote:
Quote:
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()
Grant
Guest
 
Posts: n/a
#3: Oct 16 '08

re: Create Dynamic Arrays


On Thu, 16 Oct 2008 12:53:50 -0700 (PDT), Sunny <sunnyluthra1@gmail.comwrote:
Quote:
>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.
--
http://bugsplatter.id.au
Sunny
Guest
 
Posts: n/a
#4: Oct 16 '08

re: Create Dynamic Arrays


On Oct 16, 4:05 pm, Stevo <n...@mail.invalidwrote:
Quote:
Sunny wrote:
Quote:
Hi,
>
Quote:
Is there a way in javascript to create Dynamic arrays or arrays on
fly.
Something Like:
var "ptsgN"+sd = new Array();
>
Quote:
Here sd is incrementing by 1.
>
Quote:
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();
....
>
Quote:
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...
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#5: Oct 16 '08

re: Create Dynamic Arrays


Sunny wrote:
Quote:
Is there a way in javascript to create Dynamic arrays or arrays on
fly.
In ECMAScript implementations, arrays are dynamic by default.
Quote:
Something Like:
var "ptsgN"+sd = new Array();
>
Here sd is incrementing by 1.
Array object references can be elements of arrays.
Quote:
[...]
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$8300dec7@news.demon.co.uk>
Closed Thread