Technically, as per the _javascript_ spec (that is, the ECMAScript spec), the for/in loop iterates over the properties of an object, _not_ the items of an array.

As Prototype extends the Array prototype with all sorts of useful functionality, you'll get these additional properties because of the for/in loop used incorrectly. See the other replies for the Prototypish way of doing loops.

-Thomas


Am 21.06.2006 um 00:21 schrieb Keith Davis:

function CreateTOC(){
       
        var $aTOC = document.getElementsByClassName('tocitem');
       
        var $temp = '';
       
        if(isArray($aTOC)){
               
                for($t in $aTOC){
               
                        $temp += 't=' + $t + ', ' + $aTOC[$t].name + '<BR>';
                       
                        }
                       
                $('test1').innerHTML = $temp;
                       
                }

        }


When I run this code as you see it, this is the result:

t=indexOf, undefined
t=without, undefined
t=flatten, undefined
t=compact, undefined
t=last, undefined
t=first, undefined
t=clear, undefined
t=_each, undefined
t=_reverse, undefined
t=entries, undefined
t=member, undefined
t=select, undefined
t=find, undefined
t=map, undefined
t=inspect, undefined
t=zip, undefined
t=toArray, undefined
t=sortBy, undefined
t=reject, undefined
t=pluck, undefined
t=partition, undefined
t=min, undefined
t=max, undefined
t=invoke, undefined
t=inject, undefined
t=include, undefined
t=grep, undefined
t=findAll, undefined
t=detect, undefined
t=collect, undefined
t=any, undefined
t=all, undefined
t=each, undefined
t=0, #Assessments Instruments
t=1, chiefcomplaint
t=2, History of Present Injury

The only tocitem's are the last three in that list. Where is the rest of that array coming from?



_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to