前端建立map、遍历map

前端建立、遍历map集合前端

var dataMap = {
    props: {},
    Set: function (key, value) {
        this.props[key] = value
    },
    Get: function (key) {
        return this.props[key]
    },
    Contains: function (key) {
        return this.props[key] == null ? false : true
    },
    Remove: function (key) {
        delete this.props[key]
    }
}

前端建立map集合,而且附带了set、get、contains、remove方法this

方法使用:code

dataMap.Set(“id”, "test_id");

前端遍历map集合:rem

for(var prop in map){get

    if(map.hasOwnProperty(prop)){io

        console.log('key is ' + prop +' and value is' + map[prop]);console

    }function

}test

相关文章
相关标签/搜索