반응형
자바스크립트 커스텀 Map 만들기
Map = function(){
this.map = new Object();
};
Map.prototype = {
put : function(key, value){
this.map[key] = value;
},
get : function(key){
return this.map[key];
},
containsKey : function(key){
return key in this.map;
},
containsValue : function(value){
for(var prop in this.map){
if(this.map[prop] == value) return true;
}
return false;
},
isEmpty : function(key){
return (this.size() == 0);
},
clear : function(){
for(var prop in this.map){
delete this.map[prop];
}
},
remove : function(key){
delete this.map[key];
},
keys : function(){
var keys = new Array();
for(var prop in this.map){
keys.push(prop);
}
return keys;
},
values : function(){
var values = new Array();
for(var prop in this.map){
values.push(this.map[prop]);
}
return values;
},
size : function(){
var count = 0;
for (var prop in this.map) {
count++;
}
return count;
}
};
var map = new Map();
반응형
'Programming Bookmark > JavaScript' 카테고리의 다른 글
node mariadb 연결(npm install mariadb) 연결이 되지 않는다... (0) | 2020.07.06 |
---|---|
Node.js 개인 개발 환경 출력 화면 (0) | 2020.06.10 |
자바스크립트 날짜 스트링으로 출력, 날짜형식 yyyyMmDdHhMm 형식으로 toString 하기 (0) | 2019.03.28 |
자바스크립트 Date 객체를 prototype을 통해 시간/날짜 더하기 (0) | 2019.03.28 |
HTML CSV 파일로 다운로드 하기 - 라이브러리 사용 ( Html csv export ) (0) | 2019.01.08 |