Array
object. They simply rely on the fact that object.PRoperty
is the same as object["property"]
. This means that the length
property is not used, nor do any Array
methods (sUCh as join
) do anything. In fact, it is better to create the associative array using the generic Object()
constructor to make this clearer.The way to iterate over the items in an associate array is to use the for (value in array)
construct, allowing you to access each item's value via array[value]
. It appears that the order in which properties (i.e. items) are traversed is implementation dependent. The ECMAScript specification is pretty vague on the matter, saying (in section 12.6.4) "Get name of the next property of [the object] that doesn't have the DontEnum attribute. If there is no such property, go to [the end]". Firefox, Safari and MSIE appear to traverse items in the order in which they were inserted, while KHtml (within KDE 3.1) and Opera (at least through 7.54) use a seemingly random order that presumably reflects their respective hashtable implementations.The iteration order can be tested using a very simple code snippet such as this (click here to run it):var items = {"dioxanes": 0, "shunning": 1, "plowed": 2,新闻热点
疑难解答