zoukankan      html  css  js  c++  java
  • 自定义JS Map 函数

    // 自定义JS Map 函数
    function Map() {
    var map = function (key, value) {//键值对
    this.key = key;
    this.value = value;
    }
    var put = function (key, value) {//添加键值对

    this.arr[this.arr.length] = new map(key, value);
    }
    var remove = function (key) {//删除key="key"的键值对,返回value值
    for (var i = 0; i < this.arr.length; i++) {
    var temp = this.arr.pop();
    if (this.arr[i].key === key) {

    return this.arr[i].value;
    }
    this.arr.push(temp);
    }
    return null;
    }
    var getKey = function (value) {//返回key对应的value值
    for (var i = 0; i < this.arr.length; i++) {
    if (this.arr[i].value === value)
    return this.arr[i].key;
    }
    return null;
    }
    var getValue = function (key) {//返回value对应的key值
    for (var i = 0; i < this.arr.length; i++) {
    if (this.arr[i].key === key)
    return this.arr[i].value;
    }
    return null;
    }
    var getSize = function () {//返回容器大小
    return this.arr.length;
    }

    var show = function () {//打印容器内容
    var string = "";
    for (var i = 0; i < this.arr.length; i++) {
    string += (this.arr[i].key + ":" + this.arr[i].value + " ");
    }
    alert(string);
    }
    this.arr = new Array();
    this.remove = remove;
    this.put = put;
    this.show = show;
    this.getKey = getKey;
    this.getValue = getValue;
    this.getSize = getSize;

    }

  • 相关阅读:
    dstat
    centos安装指定版本的golang
    APP防CC为什么复杂
    火狐浏览器的书签如何自动在新窗口打开?
    linux jdk版本随时切换
    centos7 yum安装java环境
    kangle清除缓存接口
    CC攻击原理及防范方法
    GET 和 POST 的区别 以及为什么 GET请求 比 POST请求 更快
    HTTP缓存机制
  • 原文地址:https://www.cnblogs.com/90nice/p/9524192.html
Copyright © 2011-2022 走看看