Dictionary of js

Posted 柠檬张先生

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dictionary of js相关的知识,希望对你有一定的参考价值。

function Dictionary() {
    this.datastore = new Array();
};
Dictionary.prototype = {
    constructor: Dictionary,
    add: function(key, value) {
        this.datastore[key] = value;
    },
    find: function(key) {
        return this.datastore[key];
    },
    remove: function(key) {
        delete this.datastore[key];
    },
    showAll: function() {
        var _this = this;
        Object.keys(this.datastore).sort().forEach(function(val, key) {
            console.log(val + " -> " + _this.datastore[val]);
        });
    },
    count: function() {
        var n = 0;
        Object.keys(this.datastore).forEach(function(val, key) {
            ++n;
        });
        return n;
    },
    clear: function() {
        var _this = this;
        Object.keys(this.datastore).forEach(function(val, key) {
             delete _this.datastore[val];
        });
    }
};
var telephoneBook = new Dictionary();
telephoneBook.add(‘Tom‘, 13713750081);
telephoneBook.add(‘Bom‘, 13713550081);
telephoneBook.add(‘Cindy‘, 43713750081);
telephoneBook.showAll();

  

以上是关于Dictionary of js的主要内容,如果未能解决你的问题,请参考以下文章

如何改变 Swift Dictionary of Dictionary

Failed to convert property value of type ‘java.lang.String‘ to required type ‘int‘ for property(代码片段

报错:✘ http://eslint.org/docs/rules/indent Expected indentation of 0 s paces but found 2(代码片段

报错:✘ http://eslint.org/docs/rules/indent Expected indentation of 0 s paces but found 2(代码片段

TP5报如下的错误 Indirect modification of overloaded element of thinkpaginatorCollection has no effect(代码片段

pandas基于元组列表(list of tuples)列表词典(dictionary of lists)词典列表(list of dictionaries)构建dataframe数据实战