网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 软件工程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
本月文章推荐
.语音识别系统中增加图像识别技术.
.项目成功的12个关键原则.
.团队协作关键做好三件事&一个.
.软件项目管理的质量保证.
.将SOA引入Office应用程序桌面.
.项目管理中的(用户)需求变更控.
.让ESB与SOA同步.
.UML组件图详解(1).
.CMM简介.
.多相晶粒图像分析中复杂晶界的提.
.软件需求说明书.
.回顾2005 开源软件进入SOA.
.黑盒测试和白盒测试.
.一场与社会工程学骗子的斗争.
.谈谈软件开发中的调研对象与被调.
.软件测试概述.
..NET 2.0 中对配置文件的读写.
.需求分析的20条法则.
.经典的软件质量保证检查过程(1).
.构建可“复用”的软件测试环境.

JavaScript Associative Arrays

发表日期:2008-3-23



  URL: http://persistent.info/archives/2004/08/27/js-associative-arrays

There seems to be some confusion regarding associative arrays in javascript (i.e. doing searches on the matter turns up many pages giving wrong information). First of all, these arrays (which act as hash tables) have nothing to do with the built-in 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,
"hoodlumism": 3, "cull": 4, "learnings": 5,
"transmutes": 6, "cornels": 7, "undergrowths": 8,
"hobble": 9, "peplumed": 10, "fluffily": 11,
"leadoff": 12, "dilemmas": 13, "firers": 14,
"farmworks": 15, "anterior": 16, "flagpole": 17};

listString = "";
for (var Word in items)
listString += items[word] + ", ";

alert(listString); If the list of numbers appears in ascending order,
then the browser preserves the insertion order. If you are in fact looking to traverse the object's properties in the order they were inserted in, regardless of browser implementation, you'll have to create a (possibly double) linked list that you can use to jump from object to object.
上一篇:(Javascript)prototype的一个优势也是缺点 人气:561
下一篇:如何建立Web服务 人气:500
浏览全部软件工程的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐