Hello,
I normally use the first loop to cycle thru elements on a form. However, I thought the second method was equivalent, yet the second method loops twice as many times as the first. What I am not understanding?
var formElements = forms.test_form.elements;
for (var i = 0; i < formElements.length; i++)
{
application.output(formElements[i].getName());
}
application.output("\n");
for (var i in formElements)
{
application.output(formElements[i].getName());
}
Hi Sean
I can’t comment on difference between your loops but for info I have run into an occasional problem on 3.0rc1
This code will run fine for a time but after returning from Layout mode sometimes fails at the getName line.
for ( var i in elements)
{
if (elements[i].getName().slice(0,3) == 'tab')
. . . . . . .
Understand the following code is recommended
var vElemArray = elements.allnames
for (var i=0 ; i<vElemArray.length ; i++)
{
if (vElemArray[i].getName().slice(0,3) == 'tab')
{
.....
Might even run quicker in your tests . . . .
Regards
Graham Greensall
Worxinfo Ltd
Hi Graham,
I’ll just stick with the first loop, but the second one just looks more elegant ![Smile :)]()
Anyway, I just hope there isn’t a generic problem when looping thru objects using the second method.