js模拟Map对象,实现key---value
js模拟Map对象,实现key---value
根据java中map的属性,实现key----value保存
function Map() {
var struct = function (key, value) {
this.key = key;
this.value = value;
}
var put = function (key, value) {
for (var i = 0; i < this.arr.length; i++) {
if (this.arr[i].key === key) {
this.arr[i].value = value;
return;
}
}
this.arr[this.arr.length] = new struct(key, value);
}
var get = function (key) {
for (var i = 0; i < this.arr.length; i++) {
if (this.arr[i].key === key) {
return this.arr[i].value;
}
}
return null;
}
var remove = function (key) {
var v;
for (var i = 0; i < this.arr.length; i++) {
v = this.arr.pop();
if (v.key === key) {
continue;
}
this.arr.unshift(v);
}
}
var size = function () {
return this.arr.length;
}
var isEmpty = function () {
return this.arr.length <= 0;
}
this.arr = new Array();
this.get = get;
this.put = put;
this.remove = remove;
this.size = size;
this.isEmpty = isEmpty;
}
js模拟Map对象,实现key---value的更多相关文章
- 在js中将map对象转换成json 和 js对cookie的操作
在js中将map对象转换成json //msp转objectlet obj= Object.create(null); for (let[k,v] of map) { obj[k] = v; }//o ...
- Js中Map对象的使用
Js中Map对象的使用 1.定义 键/值对的集合. 2.语法 mapObj = new Map() 3.备注 集合中的键和值可以是任何类型.如果使用现有密钥向集合添加值,则新值会替换旧值. 4.属性 ...
- js 操作map对象
转自:http://smallvq123.javaeye.com/blog/823923 /* * Map对象,实现Map功能 * * * size() 获取Map元素个数 * isEmpty() 判 ...
- js遍历删除对象的key
// 如果用户没有填写值,则删除对象的key. Object.keys(obj).forEach( (key) => { if (!obj[key]) { // !obj[key]表示 ...
- Js 遍历json对象所有key及根据动态key获取值
var obj = {}; for(var k in obj) { //遍历对象,k即为key,obj[k]为当前k对应的值 console.log(obj[k]); } 文章来自:https://z ...
- java根据value获取Map对象的key
Map<String, String> map= new HashMap<String,String>(); for(Map.Entry<String, String&g ...
- js 获取json对象的Key、value(js遍历json对象的key和value)
<script type="text/javascript"> getJson('age'); function getJson(key){ "," ...
- js 获取json对象的Key、value
<script type="text/javascript"> getJson('age'); function getJson(key){ var jsonObj={ ...
- js 模拟java 中 的map
//js模拟map Map = { obj : {}, put : function(key , value){ this.obj[key] = value; }, get : function(ke ...
随机推荐
- OpenJudge/Poj 2000 Gold Coins
1.链接地址: http://bailian.openjudge.cn/practice/2000 http://poj.org/problem?id=2000 2.题目: 总Time Limit: ...
- Unable to make the session state request to the session state server处理方法
Server Error in '/' Application. Unable to make the session state request to the session state serve ...
- 由Double类型数据到数据的格式化包java.text
需求:Double类型数据截取操作保留两位小数 解决方案: java.text.DecimalFormat df =new java.text.DecimalFormat("#.00&quo ...
- openwrt虚拟机的network unreachable
之前在hyper-v中装了openwrt的ATTITUDE ADJUSTMENT (12.09, r36088)这个最新版本 我之前的文章有提到怎么安装 link 但是发现用opkg update不能 ...
- 不使用border-radius,实现一个可复用的高度和宽度都自适应的圆角矩形
现在css3支持圆角矩形,但是为了兼容性问题,虽然比较麻烦,但还是有必要了解一下以下方法. 在一个div内,包含8个div,控制这个8个div的height.margin以及border属性值,以达到 ...
- Windows操作系统常用快捷键
复制:ctrl+c 剪切:ctrl+x 粘贴:ctrl+v 全选:ctrl+a 撤消:ctrl+z 保存:ctrl+s 运行:win+r ...
- Unity3d Shader开发(三)Pass(Blending )
混合被用于制作透明物体. 当图像被渲染时,所有着色器被执行以后,所有贴图被应用后,像素将被写到屏幕.他们是如何通过Blend命令的控制和已有的图像合并呢? Syntax 语法 Blend Off Tu ...
- SIAlertView
SIAlertView是AlertView的替代产品 的效果比较多 . 使用实例: SIAlertView *alertView = [[SIAlertView alloc] initWithTitl ...
- Memcached(七)Memcached的并发实例
1. Memcached是什么?Memcached是分布式的内存对象缓存系统. 2. Memcached的基本数据结构是什么?Memcached是基于Key/Value对的HashMap.每一对,都 ...
- js 拼接 三列做为一行
function Ajax_GetCourseAndResource(data) { $(".ol-course-list").empty(); var html = " ...