JS Building Map and List

Source: Internet
Author: User

//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.