//Building a mapfunctionMap () { This. arr =NewArray (); varstruct =function(key, value) { This. Key =key; This. Value =value; }; This. KeySet =function() { varArrkeys =NewArray (); for(vari = 0; I < This. arr.length; i++) {Arrkeys.push ( This. Arr[i].key); } returnArrkeys; }; This. put =function(key, value) { for(vari = 0; I < This. arr.length; i++) { if( This. Arr[i].key = = =key) { This. Arr[i].value =value; return; } } This. arr[ This. arr.length] =Newstruct (key, value); }; This. get =function(key) { for(vari = 0; I < This. arr.length; i++) { if( This. Arr[i].key = = =key) { return This. Arr[i].value; } } return NULL; }; This. values=function(){ varValue=[] for(vari = 0; I < This. arr.length; i++) {Value.push ( This. Arr[i].value); } returnValue.join (","); }; This. remove =function(key) {varv; for(vari = 0; I < This. arr.length; i++) {v= This. Arr.pop (); if(V.key = = =key) { Continue; } This. Arr.unshift (v); } }; This. Size =function() { return This. Arr.length; }; This. IsEmpty =function() { return This. arr.length <= 0; }; } /** * JS Implementation list **/ functionList () { This. Value = []; /*Add*/ This. Add =function(obj) {return This. Value.push (obj); }; /*size*/ This. Size =function() { return This. Value.length; }; /*returns the value of the specified index*/ This. get =function(index) {return This. Value[index]; } /*returns the index of the specified object*/ This. indexOf =function(obj) { for(varIinch This. Value) { if(obj = = This. Value[i]) { returni; } } }; /*Delete the value of the specified index*/ This. remove =function(index) { This. Value.splice (index,1); return This. Value; }; /*Delete all Values*/ This. RemoveAll =function() { return This. Value = []; }; /*whether to include an object*/ This. Constains =function(obj) { for(varIinch This. Value) { if(obj = = This. Value[i]) { return true; } Else { Continue; } } return false; }; /*whether to include an object*/ This. GetAll =function() { varAllinfos = ' '; for(varIinch This. Value) { if(I! = (value.length-1) ) {Allinfos+= This. value[i]+ ","; }Else{Allinfos+= This. Value[i]; }} alert (Allinfos); returnAllinfos + = This. value[i]+ ",";; }; }
JS Building Map and List