function Map() {
this.elements = new Array();
//得到map的大小
this.size = function() {
return this.elements.length;
}
//判断是否为空
this.isEmpty = function() {
return (this.elements.length < 1);
}
//清空
this.clear = function() {
this.elements = new Array();
}
//放进map一个对象
this.put = function(_key, _value) {
this.elements.push( {
key : _key,
value : _value
});
}
//根据键去除一个对象
this.remove = function(_key) {
var bln = false;
try {
for (i = 0; i < this.elements.length; i++) {
if (this.elements[i].key == _key && typeof this.elements[i].key == typeof _key) {
this.elements.splice(i, 1);
return true;
}
}
} catch (e) {
bln = false;
}
return bln;
}
//根据键得到一个对象
this.get = function(_key) {
try {
for (i = 0; i < this.elements.length; i++) {
if (this.elements[i].key == _key && typeof this.elements[i].key == typeof _key) {
return this.elements[i].value;
}
}
} catch (e) {
return null;
}
}
//返回指定索引的一个对象
this.element = function(_index) {
if (_index < 0 || _index >= this.elements.length) {
return null;
}
return this.elements[_index];
}
//是否包含键
this.containsKey = function(_key) {
var bln = false;
try {
for (i = 0; i < this.elements.length; i++) {
if (this.elements[i].key == _key && typeof this.elements[i].key == typeof _key) {
bln = true;
}
}
} catch (e) {
bln = false;
}
return bln;
}
//是否包含值
this.containsValue = function(_value) {
var bln = false;
try {
for (i = 0; i < this.elements.length; i++) {
if (this.elements[i].value == _value && typeof this.elements[i].value == typeof _value) {
bln = true;
}
}
} catch (e) {
bln = false;
}
return bln;
}
//得到所有的值
this.values = function() {
var arr = new Array();
for (i = 0; i < this.elements.length; i++) {
arr.push(this.elements[i].value);
}
return arr;
}
//得到所有的键
this.keys = function() {
var arr = new Array();
for (i = 0; i < this.elements.length; i++) {
arr.push(this.elements[i].key);
}
return arr;
}
}
相关文章
- 10-18js动态修改@keyframes
- 10-18vue+element-ui中上传文件使用Progress自定义实时更新进度条
- 10-18JS------获取一个时间区间的所有天
- 10-18jQuery 轮播图版本三:(jquery.SuperSlide.2.1.1.js)做轮播图,多张图向左翻页
- 10-18openlayers+turf.js绘制线缓冲区
- 10-18WebGL可视化3D绘图框架:Three.js 零基础上手实战
- 10-18three.js学习:初学three.js,从立方体开始
- 10-18我和我的小伙伴们都惊呆了!基于Canvas的第三方库Three.js
- 10-18Labview自定义控件-布尔类控件
- 10-18【带着canvas去流浪(12)】用Three.js制作简易的MARVEL片头动画(上)