Home >Web Front-end >JS Tutorial >Example of data type code similar to asp data dictionary implemented by js_javascript skills

Example of data type code similar to asp data dictionary implemented by js_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:37:391373browse

First declare an array:

Copy code The code is as follows:

var dictNew=new Array;

var key;

var value;

for (var i = 0; i <50; i ) {

//Get the key-value pairs to be added 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 exist, directly add the key value and value to the data dictionary. If the key value exists, the value value is accumulated

 if(checkHasInDict(key,dictNew)){
   dictNew[key] = num2zero(dictNew[key]) value;
 }else{
   dictNew[key] = value;
  }

}

//Value of data dictionary

function getDictValue(key,dict){

 var tempDictValue = "";

 for(var k in dict){

 if(k==key){

tempDictValue =dict[k];

return tempDictValue;

 }

 }

return tempDictValue;

}

//Check whether the key value exists in the array
function checkHasInDict(key,dict){
for(var k in dict){
if (k == key){
Return true;
}
}
return false ;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn