# Loop through array problem

**URL:** https://forum.kirupa.com/t/loop-through-array-problem/13226
**Category:** Uncategorized
**Created:** [February 10, 2003, 3:35pm UTC](https://forum.kirupa.com/t/loop-through-array-problem/13226 "2003-02-10T15:35:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chapster](https://avatars.discourse-cdn.com/v4/letter/c/958977/32.png) [@chapster](https://forum.kirupa.com/u/chapster)
#### Post date: [February 10, 2003, 3:35pm UTC](https://forum.kirupa.com/t/loop-through-array-problem/13226/1 "2003-02-10T15:35:58Z")

</div>

I’m trying to set up this loop to run through the array and add the value of i to each element in the array.  
Example: phone.tabIndex=1;  
email.tabIndex=2  
etc.  
[COLOR=orangered]  
tabArray = [phone, email, field1, field2, field3, field4, field5, field6, field7, dressBox, subjectBox];  
Selection.setFocus(field1);  
for (var i = 0; i\<tabArray.length; i++) {  
tabArray\*.tabIndex =\*+1;  
}  
[/COLOR]

When I do a  
trace(field7.tabIndex);  
it shows up 0  
What am I doing wrong. Thanks

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 10, 2003, 4:13pm UTC](https://forum.kirupa.com/t/loop-through-array-problem/13226/2 "2003-02-10T16:13:56Z")

</div>

did you do  
TabArray = New Array(); ?

I’m not sure if you HAVE to declare it, but I’ve had problems if I don’t…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 10, 2003, 4:20pm UTC](https://forum.kirupa.com/t/loop-through-array-problem/13226/3 "2003-02-10T16:20:20Z")

</div>

It doesn’t matter if I declare it or not it still doesn’t work.  
But on that question of declaring it.

```auto

tabArray = [phone, email, field1, field2, field3, field4, field5, field6, field7, dressBox, subjectBox];

```

Writing out the whole array surely declares the array no. But I still get 0 in the trace().  
It’s this part that is wrong.

tabArray\*.tabIndex =\*+1;

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 10, 2003, 4:22pm UTC](https://forum.kirupa.com/t/loop-through-array-problem/13226/4 "2003-02-10T16:22:41Z")

</div>

I cant tell what your code should be since it got cut off, but this is what you want.

for (i = 0; i \< tabArray.length; i++){  
tabArray[\*\*i].tabIndex = i;  
}

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 10, 2003, 4:30pm UTC](https://forum.kirupa.com/t/loop-through-array-problem/13226/5 "2003-02-10T16:30:33Z")

</div>

Gret thanks. That is what I was doing wrong. I was using tabArray\*.tabIndex=\*;  
Thanks again
