javascript HashMap
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javaScript" language="javascript" defer="defer">
var oMap = function(){
this.map = new Object();
}
oMap.prototype = {
put: function (key, value) {this.map[key] = value;}, // key, value 값으로 구성된 데이터를 추가
get: function (key) {return this.map[key];}, // 지정한 key값의 value값 반환
containsKey: function (key) { return key in this.map;}, // 구성된 key 값 존재여부 반환
remove: function (key) {delete this.map[key];}, // key에 해당하는 데이터 삭제
containsValue: function (value) { // 구성된 value 값 존재여부 반환
for (var prop in this.map) {
if (this.map[prop] == value) {
return true;
}
}
return false;
},
clear: function () { // 구성된 데이터 초기화
for (var prop in this.map) {
delete this.map[prop];
}
},
keys: function () { // 배열로 key 반환
var arKey = new Array();
for (var prop in this.map) {
arKey.push(prop);
}
return arKey;
},
values: function () { // 배열로 value 반환
var arVal = new Array();
for (var prop in this.map) {
arVal.push(this.map[prop]);
}
return arVal;
},
size: function () { // Map에 구성된 개수 반환
var count = 0;
for (var prop in this.map) {
count++;
}
return count;
}
}
function oraView(){
var oraMap = new oMap();
oraMap.put("abc","9999");
alert(oraMap.get("abc"));
}
</script>
</head>
<body>
<input type="button" onclick="oraView();" value="oraView" />
</body>
</html>
------------------------------------------------------------------------------------------
result :
9999