Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:37:39
Original
1355 people have browsed it

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 ;
}

Related labels:
js
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!