首页| 新闻| 科技| 人物| 科学| 话题| 运营| 设计| 开发| 服务器| 学院| 产品| 网文| 娱乐| 游戏| 图片
该类可以通过要害字(key)查找相对应的值(value),要害字的类型可以是string、number、boolean类型,值的类型不限,代码如下:
运行代码框<script>function struct(key, value){ this.key = key; this.value = value;}function setat(key, value){ for (var i = 0; i < this.map.length; i ) { if ( this.map[i].key === key ) { this.map[i].value = value; return; } } this.map[this.map.length] = new struct(key, value);}function lookup(key){ for (var i = 0; i < this.map.length; i ) { if ( this.map[i].key === key ) { return this.map[i].value; } } return null;}function removekey(key){ var v; for (var i = 0; i < this.map.length; i ) { v = this.map.pop(); if ( v.key === key ) continue; this.map.unshift(v); }}function getcount(){ return this.map.length;}function isempty(){ return this.map.length <= 0;}function classmap() { this.map = new array(); this.lookup = lookup; this.setat = setat; this.removekey = removekey; this.getcount = getcount; this.isempty = isempty;}window.{ var map = new classmap(); alert("is the map empty? " map.isempty()); // string to array map.setat("sw1", new array("sw1_1")); map.setat("sw2", new array("sw2_1", "sw2_2")); map.setat("sw3", new array("sw3_1", "sw3_2", "sw3_3")); alert(map.lookup("sw5")); // null alert(map.lookup("sw2")); // "sw2_1, sw2_2" alert(map.getcount()); // 3 // number to string map.setat(1, "sw1"); map.setat(2, "sw2"); alert(map.lookup(2)); // "sw2" map.setat(2, new array("sw2_1", "sw2_2")); alert(map.lookup(2)); // "sw2_1, sw2_2" alert(map.getcount()); // 5 // string to number map.setat("1", 1); map.setat("2", 2); alert(map.lookup("1")); // 1 alert(map.lookup(1)); // "sw1" map.setat("sw3", 33); alert(map.lookup("sw3")); // 33 alert(map.getcount()); // 7 // number to number map.setat(1, 11); map.setat(2, 22); alert(map.lookup(1)); // 11 alert(map.getcount()); // 7 map.removekey(1); alert(map.lookup(1)); // null alert(map.getcount()); // 6 // boolean to array map.setat(false, new array("false", "true")); alert(map.lookup(false)); alert(map.getcount()); // 7}</script> [ctrl a 全部选择 提示:你可先修改部分代码,再按运行]
为什么越来越多的网站域名不加
jq判断输入框必填(适合多条件搜
windows wamp中配置安装xhprof步骤
校园甜美的背影,洋溢着青春烂漫的回忆
南国有佳人,容华若桃李
游览三河古镇景点:望月阁、古民居、一人巷
大蜀山森林公园美景
路边摊小吃 酒香不怕巷子深
特色路边摊小吃 下班路上的一道美食
爷爷都是从孙子走过来的
我太帅了,睡不着咋整啊
新闻热点
疑难解答
图片精选
DW MX实例:极酷的鼠标外观-Dreamwea
DW MX实例:个性化 IE 滚动条-Dreamw
技巧:让网页中文字替代图片-Dreamwe
DW MX实例:多彩文字链接-Dreamweave
网友关注