mk*****@yahoo.com wrote:
When you use an object as an assc array as in:
var aa = new Array();
aa["peanuts"] = 2.50;
aa["popcorn"] = 3.50;
...
Is there a way to determine the number of entries?
So far I count this way: for (var x in aa) num_in_aa++;
How do you sort these? Is there a way to sort within the for/in
construct, something like
for(var x in 'sort aa') ????
JavaScript 1.7 as of Gecko 1.8.1 (e.g. in Firefox 2.0) introduces iterators
that allow you to do just that:
http://PointedEars.de/scripts/es-matrix/#i http://developer.mozilla.org/en/docs..._1.7#Iterators
Otherwise you should follow Rob's suggestion.
In addition, also because you are interested in "the number of entries", you
could construct and use a collection yourself, or use an existing
implementation, like <http://PointedEars.de/scripts/collection.js>. I have
not tested it sufficiently yet, so you might have to tweak it a bit -- any
feedback is welcome. (However, please also take note of the licensing
conditions under which it is distributed.)
HTH
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann