am****@iwc.net wrote:
Well, I did not write it. But since I am going to maintain it, do you
have a better suggestion?
You haven't described what it should do, so we can only guess at that.
As written, it won't do what it appears it is supposed to do.
It seems to be an attempt to create an array of as many empty arrays as
the value returned by document.$fm.category.options.length.
The actual outcome will be an array called group that has a length of
groups+1. It will have a single element at index groups that is an
array - the others are all undefined. Because the single element is at
index groups, the length of the array will now be groups+1 (the length
of an array is always greater than the highest index).
Whether that serves any useful purpose is impossible to tell from the
snippet provided. It is possible that some later code is based on the
fact that the length is now groups+1, so 'fixing' that may cause other
errors.
Thomas has given you one suggestion, here's another:
var group = [];
var i = document.$fm.category.options.length;
while(i--){
group[i] = [];
}
A more robust effort might be:
var group = [];
var o;
var i = ( (o = document.$fm)
&& (o = o.category )
&& (o = o.options )
&& (o = o.length )
);
while(i){
group[--i] = [];
}
But it seems rather pointless. Presumably after this an attempt will be
made to assign values to the empty arrays. The arrays could be created
then, making the above redundant.
If whatever script the posted snippet is part of actually works, that is
likely what is happening anyway.
But be warned - fixing apparently broken parts of 'working' code will
very likely cause errors elsewhere.
--
Zif