Js implementation is similar to the asp data dictionary data type code instance

  • 2020-03-30 03:49:07
  • OfStack

First declare an array:


var dictNew=new Array;  var key; var value;  for (var i = 0; i <50; i++) {   //Gets the key-value pair
to add to the data dictionary     key= jQuery("#costCodeIdId"+i).val();   value = num2zero(jQuery("#valueId"+i).val());   //Check whether the key value exists in the data dictionary. If it does not, directly add the key value and value to the data dictionary. If the key key value exists, the value value will be accumulated     if(checkHasInDict(key,dictNew)){
       dictNew[key] = num2zero(dictNew[key]) + value;
    }else{
       dictNew[key] = value;
    } }   //The value of the data dictionary function getDictValue(key,dict){   var tempDictValue = "";   for(var k in dict){     if(k==key){       tempDictValue =dict[k];       return tempDictValue;     }   }   return tempDictValue; }   //The check is whether the key value exists
in the array function checkHasInDict(key,dict){
 for(var k in dict){
  if (k == key){
   return true;
  }
 }
 return false ;
}


Related articles: