By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,742 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,742 IT Pros & Developers. It's quick & easy.

Create Dynamic Arrays

P: n/a
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.
Oct 16 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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()
Oct 16 '08 #2

P: n/a
On Thu, 16 Oct 2008 12:53:50 -0700 (PDT), Sunny <su**********@gmail.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.
--
http://bugsplatter.id.au
Oct 16 '08 #3

P: n/a
On Oct 16, 4:05 pm, Stevo <n...@mail.invalidwrote:
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...
Oct 16 '08 #4

P: n/a
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, <f8*******************@news.demon.co.uk>
Oct 16 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.