PDA

View Full Version : Please help. Array - Looping problem.



BVision
June 23rd, 2004, 12:53 AM
Origional
allLinks.push(new Link(s1[0], s1[1], s1[2], s1[3]));
allLinks.push(new Link(s2[0], s2[1], s2[2], s2[3]));
// seems to be a pattern here ??, would be nice to loop this.....
etc.....
My attempt to try to simplify this problem for(i=0;i<5;i++){
addNew = (new Link(s+i[0], s+i[1], s+i[2], s+i[3]));
allLinks[i]= addNew;}


I would like to populate 'allLinks' with objects 's'. However I have been unsuccessfull in my attempts. I need this loop to work for a a large number of items so I dont really want to have to add each individual item.

I have no more ideas, i've tried just about everything I know. Even checked out these forums for this type of problem, with no luck.

I would like to make it as simple as possible.

Thanks in Advance.
Anthony - BVision.

Johnny64
June 24th, 2004, 05:16 AM
I take it that Link is a class you made?


for(i=0;i<5;i++){
addNew = new Link(this["s"+i][0], this["s"+i][1], this["s"+i][2], this["s"+i][3]);
allLinks[i]= addNew;
}

This should work :)

BVision
June 24th, 2004, 11:40 AM
Actually, I didn't create it, I found it being used on the internet and I modified it.
However, it's really neat.. it renames each array index to whatever I want... so i dont have to remember what each of the number are....

Hey, I just tried it. However, it does not work exactly right... I had to modify 'this' to be _level0. It works just Fine now.

Thanks A million.
Anthony - BVision