JS/TS写一个Dictionary类_艾孜尔江撰稿
作者:互联网
export default class Dictionary {
private dataStore: any = new Array<any>(); // must be instatiated!
Dictionary() {
this.dataStore = [];
}
public add = (key: any, value: any) => {
this.dataStore[key] = value;
}
public find = (key: any) => {
return this.dataStore[key];
}
public getKeyByValue = (value: any) => {
for (const key in this.dataStore) {
if (this.dataStore[key] === value) {
return key;
}
}
return 'Not Found';
}
public remove = (key: any) => {
if (this.dataStore[key]) delete this.dataStore[key];
else return 'Not Found';
}
public showAll = () => {
for (const key in this.dataStore)
console.log(key + '->' + this.dataStore[key]);
}
}
标签:return,Dictionary,艾孜尔江,TS,value,public,key,dataStore,any 来源: https://blog.csdn.net/weixin_43867242/article/details/113710291