js map

 1 // js通用方法
 2
 3 // map对象定义
 4 function Map() {
 5     var struct = function(key, value) {
 6         this.key = key;
 7         this.value = value;
 8     };
 9
10     var put = function(key, value) {
11         for (var i = 0; i < this.arr.length; i++) {
12             if (this.arr[i].key === key) {
13                 this.arr[i].value = value;
14                 return;
15             }
16         }
17         this.arr[this.arr.length] = new struct(key, value);
18     };
19
20     var get = function(key) {
21         for (var i = 0; i < this.arr.length; i++) {
22             if (this.arr[i].key === key) {
23                 return this.arr[i].value;
24             }
25         }
26         return null;
27     };
28
29     var remove = function(key) {
30         var v;
31         for (var i = 0; i < this.arr.length; i++) {
32             v = this.arr.pop();
33             if (v.key === key) {
34                 continue;
35             }
36             this.arr.unshift(v);
37         }
38     };
39
40     var size = function() {
41         return this.arr.length;
42     };
43
44     var isEmpty = function() {
45         return this.arr.length <= 0;
46     };
47     this.arr = new Array();
48     this.get = get;
49     this.put = put;
50     this.remove = remove;
51     this.size = size;
52     this.isEmpty = isEmpty;
53 }
时间: 2024-08-28 12:29:38

js map的相关文章

[Immutable.js] Differences between the Immutable.js Map() and List()

The Immutable.js Map() is analogous to a Javascript Object or Hash since it is comprised of key-value pairs. The Immutable.js List() is analogous to a Javascript Array and contains many of the same native methods. Let's compare the two and dive into

[Immutable.js] Working with Subsets of an Immutable.js Map()

Immutable.js offers methods to break immutable structures into subsets much like Array--for instance it has the all powerful slice()--and unlike Array it offers functional methods like take() and skip(). You get the best of both the imperative and fu

swiper.min.js.map访问404解决办法

引用swiper后,在网站加载时浏览器控制台会报错,如下图所示: 建议不使用Source Map功能,请把js压缩文件最后一行 //# sourceMappingURL=maps/swiper.min.js.map 删掉.以免在某些浏览器出现以下提示: //# sourceMappingURL=maps/swiper.min.js.map

[Javascript] Creating an Immutable Object Graph with Immutable.js Map()

Learn how to create an Immutable.Map() through plain Javascript object construction and also via array tuples. console.clear(); // Can be an object var map = Immutable.Map({key: "value"}); console.log(map.get("key")); //"value&quo

angularjs中 *.min.js.map 404的问题

初次使用AngularJS,在chrom调试的时候,出现如下问题: GET http://localhost:63342/luosuo/visitor/js/lib/angular-animate.min.js.map 404 (Not Found) register.html:1 GET http://localhost:63342/luosuo/visitor/js/lib/angular-route.min.js.map 404 (Not Found) 百度之,原因如下: 问题解决了的感觉

js.map error

1. 问题:  1.1 通过bower install 的components 许多在运行的时候报404无法找到js.map文件, 如图: 2. 分析: 2.1 查看jQuery源码 /dist/jquery.min.map 2.2 在stackoverflow中查找到: 2.3 在项目发布的时候, 删除了js.map 文件, 所以使其报错, 文件不对应; 2.4 得出js.map文件是帮助开发人员反压缩代码用的,是一个映射文件, 对项目运行无影响; 3. 解决: 3.1 在/bower_com

js map()处理数组和对象数据

之前的文章梳理了JS数组与对象属性的遍历方法,本文介绍专门用以遍历并处理数据的map()方法. 一.原生map() map()是数组的一个方法,它创建一个新数组,其结果是该数组中的每个元素都调用一个提供的函数后返回的结果.map()里面的处理函数接受三个参数,分别指代当前元素.当前元素的索引.数组本身.(IE9以下不支持,对老旧浏览器的兼容性方法参考这里) /**** 原生map() ****/ var arrTmp = [1,2,3]; var arrDouble = arrTmp.map(f

[Immutable,js] Iterating Over an Immutable.js Map()

Immutable.js provides several methods to iterate over an Immutable.Map(). These also apply to the other immutable structures found within the Immutable.js family, such as Set and List. The primary methods are map and forEach, but we will also cover f

JS Map 和 List 的简单实现代码

javascript中是没有map和list 结构的. 本篇文章是对在JS中Map和List的简单实现代码进行了详细的分析介绍,需要的朋友参考下 代码如下: /* * MAP对象,实现MAP功能 * * 接口: * size()     获取MAP元素个数 * isEmpty()    判断MAP是否为空 * clear()     删除MAP所有元素 * put(key, value)   向MAP中增加元素(key, value)  * remove(key)    删除指定KEY的元素,成