[thelist] arrays vs. ordered collections

Tom Dell'Aringa pixelmech at yahoo.com
Tue Jul 29 11:23:59 CDT 2003


Greets,

Working on an article on client side sorting and having a bit of
trouble with something.

In JavaScript we have the array object. This, according to Danny G.
is a "data structure provided for storing and manipulating ordered
collections of data."

In the DOM, we can retrieve a collection of objects using the
getElementsByTagName(tagString) method. According to MSDN, the method
'Retrieves a collection of objects based on the specified element
name'. The W3C further defines this returned collection as a
NodeList: "The NodeList interface provides the abstraction of an
ordered collection of nodes..."

The question is, is this so called ordered collection a TRUE ordered
collection in the JS sense? It seems NOT to be.

For example, I have said ordered collection of rows. If I try to
manipulate this collection with array methods such as sort() and
reverse(), they do not seem to work. What's worse - the script
sometimes doesn't throw an error (depending on how you are using it.)

When I try a simple reverse() on my rows collection, I get a "object
doesn't support this property or method." error.

If, however, I transfer this collection to a JS array:

rowArray = New Array();
rowArray[i] = rows[i].cloneNode(true);

Then I can do all I want with it. So the I guess my question is
"what's the difference" between the two? The 'ordered collection'
must not be the same as the 'ordered collection' that JS refers to. I
simply want to be able to explain this difference in my article but
having a heck of a time finding any documentation on the issue.

Thanks! Sorry for the long post.

Tom

=====
http://www.pixelmech.com/ :: Web Development Services
http://www.DMXzone.com/ :: Premium Content Author / JavaScript / Every Friday!
http://www.maccaws.com/ :: Group Leader
[Making A Commercial Case for Adopting Web Standards]

"That's not art, that's just annoying." -- Squidward


More information about the thelist mailing list