for in and arrays

Giganews Newsgroups
Subject: for in and arrays
Posted by:  Jeff Thies (cyberje…
Date: Mon, 08 Sep 2003

I think I am misundertanding how "in" works.

I thought I could do this:

var div_array=document.getElementsByTagName('div');

for(var el in div_array){
// I thought el would be an element of that array
// doing this: alert(el) yields either the elements ID or "length"
// why is that?

This works, which I thought was the same.

for(var i=0; i< div_array.length; i++){
var el=div_array[i];