Create Dynamic Arrays

S

Sunny

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.
 
G

Grant

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.
 
S

Stevo

Sunny said:
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()
 
S

Sunny

Sunny said:
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...
 
T

Thomas 'PointedEars' Lahn

Sunny said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,138
Messages
2,570,802
Members
47,348
Latest member
nethues

Latest Threads

Top